Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-18308

Poor argument checks for `--tarfile` option in `drush civicrm-upgrade` leads to removal of civicrm module files

    Details

    • Versioning Impact:
      Patch (backwards-compatible bug fixes)
    • Documentation Required?:
      None
    • Funding Source:
      Needs Funding

      Description

      The `--tarfile` option is required for using drush to upgrade civicrm via the command:

      drush civicrm-upgrade --tarfile=/path/to/civicrm.tar.gz

      If the `--tarfile` switch is eliminated entirely, the command exits with a helpful error:
      Tarfile not specifed. [error]
      However, if one uses the common unix convention of following a flag with a space rather than `=`, the command does not exit – rather, it starts the upgrade process, but errors out:

      user@host:~/public_html$ drush civicrm-upgrade --tarfile ~/upgrades/civicrm-4.7.4-drupal.tar 
      
      The upgrade process involves - 
      1. Backing up current CiviCRM code as => /var/www/../backup/modules/20160328220114/civicrm
      2. Backing up database as => /var/www/../backup/modules/20160328220114/civicrm.sql
      3. Unpacking tarfile to => /var/www/sites/all/modules/
      4. Executing civicrm/upgrade?reset=1 just as a browser would.
      
      Do you really want to continue? (y/n): y
                                                                                            [ok]
      1. Code backed up.
      Database dump saved to                                                                [success]
      /var/www/../backup/modules/20160328220114/civicrm.sql
      2. Database backed up.                                                                [ok]
      3. Tarfile unpacked.                                                                  [ok]
      require_once(CRM/Core/Config.php): failed to open stream: No such file or directory   [warning]
      civicrm.drush.inc:666
      PHP Fatal error:  require_once(): Failed opening required 'CRM/Core/Config.php' (include_path='.:/var/www/sites/all/modules/civicrm:/var/www/sites/all/modules/civicrm/packages:/var/www/sites/all/modules/civicrm/vendor/tecnickcom:/var/www/sites/all/modules/civicrm/vendor/phpseclib/phpseclib/phpseclib:.:/var/www/sites/all/modules/civicrm:/var/www/sites/all/modules/civicrm/packages:.:/usr/share/php:/usr/share/pear') in /var/www/sites/all/modules/civicrm/drupal/drush/civicrm.drush.inc on line 666
      Drush command terminated abnormally due to an unrecoverable error.                    [error]
      Error: require_once(): Failed opening required 'CRM/Core/Config.php'
      (include_path='.:/var/www/sites/all/modules/civicrm:/var/www/sites/all/modules/civicrm/packages:/var/www/sites/all/modules/civicrm/vendor/tecnickcom:/var/www/sites/all/modules/civicrm/vendor/phpseclib/phpseclib/phpseclib:.:/var/www/sites/all/modules/civicrm:/var/www/sites/all/modules/civicrm/packages:.:/usr/share/php:/usr/share/pear')
      in
      /var/www/sites/all/modules/civicrm/drupal/drush/civicrm.drush.inc,
      line 666
      

      I believe the cause is that the checks for the presence of the `--tarfile` switch check only that it exists, and not that it "contains" a tarfile as a value. The code uses ``drush_get_option('tarfile', FALSE);``, which returns the value "1" for the bare switch without "=". The result is that drush removes the civicrm module directory, and then tries to unpack the non-existent tarfile "1" into its place. As the upgrade continues, it fails when trying to require a file from the now non-existent module directory.

      Ideally, the drush handler would tolerate both the --tarfile=civicrm.tar.gz and --tarfile civicrm.tar.gz variants. Failing that, it should exit with an error if the latter form is used, rather than breaking the civicrm installation.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              cfd charlie
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: