Showing posts with label software development. Show all posts
Showing posts with label software development. Show all posts

Monday, September 30, 2024

Restore Joomla 4 Manually

This post has info on manually restoring a Joomla 4.3.4 set-up across two servers. While both are Linux systems the configuration differ slightly including the OS, Php , DB, etc. Various issues were faced & overcome in doing the restoration.

Background info:

- Source:
Ubuntu 22.04, Php 8.2, Joomla 4.3.4, Apache, Maria DB, Addon Plugins (AddToAny, LazyDb, Komento, SexyPolling)

- Destination:
Ubuntu 20.04, Php 7.4, Joomla 4.3.4, Apache, MySql 8.0

- Latest DB dump & htdocs folder (including all files, modules, plugins, media, images etc.) from Source was transferred to Destination server via Ftp before hand.

Steps:

1) DB Import

    1.1) Create user, db, grant all permission to user. 

    1.2) Import data to the created db from the latest DB dump of the source.
 
        1.2.1) ERROR 1366 (HY000) at line 2273: Incorrect integer value: '' for column 'checked_out' at row 1. Solution is to set NO_ENGINE_SUBSTITUTION & then import:

            SET @@GLOBAL.sql_mode= 'NO_ENGINE_SUBSTITUTION';

    1.3) ERROR 1101 (42000) at line 10692: BLOB, TEXT, GEOMETRY or JSON column 'country' can't have a default value

        - Using the solution found online & the DB dump sql import script was changed to set DEFAULT values for the problematic text columns country, city, etc
    

         // Modify the sexypolling plugin CREATE TABLE script:
            CREATE TABLE `#_sexy_votes` (
              `id_vote` int(10) unsigned NOT NULL AUTO_INCREMENT,
                  ....
              `country` text NOT NULL DEFAULT (_utf8mb4'Unknown'),
              `city` text NOT NULL DEFAULT (_utf8mb4'Unknown'),
              `region` text NOT NULL DEFAULT (_utf8mb4'Unknown'),
              `countrycode` text NOT NULL DEFAULT (_utf8mb4'Unknown'),

              PRIMARY KEY (`id_vote`),
                  .....

            ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;

2) Download Joomla_4.3.4-Stable-Full_Package.zip from joomla.org
    2.1) Unzip Joomla_4.3.4-Stable-Full_Package.zip to /var/www/html & rename folder to <site_name>

    2.2) Set up site configuration.php (/var/www/html/<site_name>/configuration.php)
        - Add db, username, password
        - Add tmp_path & log_path in

        public $log_path = '/var/www/html/<site_name>/administrator/logs';
          public $tmp_path = '/var/www/html/<site_name>/tmp';


3) Restore Joomla modules, plugins, languages, etc from file system Ftp backup location of Source.

4) Additional system settings on Destination


    4.1) Add missing Php modules: "Call to undefined function" error

        4.1.1) simplexml_load_file()
            sudo apt-get install php7.4-xml

        4.1.2) "IntlTimeZone" module missing
            sudo apt-get install php7.4-intl

    4.2) Increase Php upload limit (/etc/php/7.4/apache2/php.ini)

          post_max_size = 38M
            upload_max_filesize = 32M


    4.3) Restart apache
          sudo systemctl reload apache2
 

5) Recovering from J4 Red Error Page of death

    5.1) Redirection to installation/index.php:

    - With an error "500 - Whoops, looks like something went wrong".
    - Needed to delete the installation folder, to stop the redirection.

    5.2) Next, 404 Component not found error on the home page: 
 

    ---
        404 **Component not found.**

        Call stack
        #     Function     Location
        1     ()     JROOT/libraries/src/Component/ComponentHelper.php:296
        2     Joomla\CMS\Component\ComponentHelper::renderComponent()     JROOT/libraries/src/Application/SiteApplication.php:210
        3     Joomla\CMS\Application\SiteApplication->dispatch()     JROOT/libraries/src/Application/SiteApplication.php:251
        4     Joomla\CMS\Application\SiteApplication->doExecute()     JROOT/libraries/src/Application/CMSApplication.php:293
        5     Joomla\CMS\Application\CMSApplication->execute()     JROOT/includes/app.php:61
        6     require_once()     JROOT/index.php:32
    ---
 

    5.3) Checked DB connections using a custom php script:

No issues connecting to DB with username/ password!

    5.4) Enable Debugging/ Logging:
        

        5.4.1) Logging in php.ini (/etc/php/7.4/apache2/php.ini)
            ----Turn on logging-----
               display_errors = On
               html_errors = On
               display_startup_errors = On
               log_errors = On
               error_log = /var/log/apache2/php_errors.log


        5.4.2) Logging in configuration.php (/var/www/html/<site_name>/configuration.php)
            // Change to true from false
                public $debug = true;
                public $debug_lang = true;

                // Change to 'maximum' from 'default'
                public $error_reporting = 'maximum';
    
                // Change to 1 from 0
                public $log_everything = 1;


    With those J! Info started showing up in the browser along with the error stack trace & queries.

    5.5) Root cause analysis

        5.5.1) Checked the specific php libraries:
            libraries/src/Component/ComponentHelper.php:296
            libraries/src/Application/SiteApplication.php:210, etc..

    - Using var_dump($component), on SiteApplication.php:210 found: 

           $component = NULL

        - The same '$component = "com_content"' on the home page of a default Joomla application (unzip Joomla 4.3.4 zip & install & check value on Joomla home page).

        - Test with hard coded $component = "com_content" in libraries/src/Application/SiteApplication.php:210

                if(empty($component)){
                     $component = "com_content";
         
       }


        - With this 404 was gone & a broken site home page came up with a few Category links listed out

        - Clicking on Category link was showing that "No Article linked to Category", despite there being several Articles imported from source db dump.

        5.5.2) Localizing issue with Content/ Article loading:
        - Hit the direct Article url:
            http://<site_name>/index.php?option=com_content&view=article&id=<article_id>

        - This gave another error"404 Article not found", though the specific <article_id> was present in the database.

        - J! Info provided the corresponding php file and db query used to fetch article by id which was giving no result

    5.5.3) Issue with imports of all "datetime DEFAULT NULL" fields

    - On exploring the query further, it was seen to have checks for publish_up & publish_down dates. These needed to be either NULL or set to a date earlier (/later) than date NOW for publish_up (/publish_down).

    - In the "#_content" table publish_up & publish_down dates values were showing as "0000-00-00 00:00:00" (i.e. were imported as 0) in place of NULL.
This was causing all records being filtered out.

    - It also meant that wherever the "datetime default NULL" fields were imported the same issue was happening. 

        - A check revealed 30 other J! tables with the same issue.
 
        - Prepared a script to update each of these datetime fields to NULL in the 30 tables.
            UPDATE `#_content` SET `checked_out_time` = NULL, `publish_up` = NULL, `publish_down` = NULL;

            UPDATE `#_categories` SET `checked_out_time` = NULL;
                                                                     .... 
for all the affected tables!

With that the issue was resolved & site home page became functional!

Tuesday, April 30, 2019

996.ICU

About time the revolution reaches our shores. Concerns from the 996.ICU movement most certainly apply here. There's additionally the grind from the 3+ hours of daily travel time between workplace & home in the typically over-crowded metros.

The demands for a well balanced work life (wbl) are totally justified. 955 schedule, flexi-hours, work from home, are not concepts to be just spoken of but to be put to practice. Let's work smart, live healthy & be happy!

Monday, March 4, 2019

AB Testing To Establish Causation

A/B testing is a form of testing performed to compare the effectiveness of different versions of a product with randomly distributed (i.i.d.) end-user groups. Each group gets to use only one version of the product. Assignment of any particular user to a specific group is done at random, without any biases, etc. User composition of the different groups are assumed to be similar, to the extent that switching the version of the products between any two groups at random would make no difference to the overall results of the test.

A/B testing is an example of a simple randomized control trial . This sort of tests help establish causal relationship between a particular element of change & the measured outcome. The element of change could be something like change of location of certain elements of a page, adding/ removing a feature of the product, conversion rate, and so on. The outcome could be to measure the impact on additional purchase, clicks, time of engagement, etc.

During the testing period, users are at randomly assigned to the different groups. The key aspect of the test is the random assignment of users being done in real-time of otherwise similar users, so that no other unknown confounding factors (demographics, seasonality, tech. competence, background, etc.) have no impact on the test objective. When tested with a fairly large number of users, almost every group will end-up with a good sample of users that are representative of the underlying population.

One of the groups (the control group) is shown the baseline version (maybe an older version of an existing product) of the product against which the alternate versions are compared. For every group the proportions of users that fulfilled the stated objective (purchased, clicked, converted, etc.) is captured.

The proportions (pi) are then used to compute the test statistics Z-value (assuming a large normally distributed user base), confidence intervals, etc. The null hypothesis being that the proportions (pi) are all similar/ not significantly different from the proportion of the control group (pc).

For the two version A/B test scenario

   Null hypothesis H0(p1 = pc) vs. the alternate hypothesis H1(p1 != pc).

   p1 = X1/ N1 (Test group)
   pc = Xc/ Nc (Control group)
   p_total = (X1 + Xc)/(N1 + Nc) (For the combined population) ,
            where X1, Xc: Number of users from groups test & control that fulfilled the objective,
                & N1, Nc: Total number of users from test & control group

  Z = Observed_Difference / Standard_Error
    = (p1 - pc)/ sqrt(p_total * (1 - p_total) * (1/N1 + 1/Nc))



The confidence level for the computed Z value is looked up in a normal table. Depending upon whether it is greater than 1.96 (or 2.56) the null hypothesis can be rejected with a confidence level of 95% (or 99%, or higher). This would indicate that the behavior of the test group is significantly different from the control group, the likely cause for which being the element of change brought in by the alternate version of the product. On the other hand, if the Z value is less than 1.96, the null hypothesis is not rejected & the element of change not considered to have made any significant impact on fulfillment of the stated objective.

Thursday, June 18, 2015

Lftp

Lftp a handy utility for all kinds of ftp, sftp, and other file transfer use-cases from the command-line on a *nix system. Give it a shot if there's ever a need..

Thursday, September 12, 2013

Transparently


While doing software development you might hear of change being introduced "transparently". What does this mean?

Transparency in this context is similar to how a looking glass is transparent. One can barely make out that it exists. Think of a biker who pulls down the glass visor of his helmet when troubled by wind blowing into his eyes. His sight of the road & beyond continue to function without his noticing the transparent visor layer in-between.

Similarly, when a change in introduced transparently on the server side, it means the dependent/ client side applications needn't be told/ made aware of this change on the server side. The old interfaces continue to work as is, communication protocols remain the same, and so on.

The above kind of transparency is different from the transparency of a "transparent person" or a "transparent deal" or a "white box system", where the internals (like thoughts, implementation, ideas, details, etc.) are visible.