| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.4 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2013 | |
| 7 | +--------------------------------------------------------------------+ |
| 8 | | This file is a part of CiviCRM. | |
| 9 | | | |
| 10 | | CiviCRM is free software; you can copy, modify, and distribute it | |
| 11 | | under the terms of the GNU Affero General Public License | |
| 12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
| 13 | | | |
| 14 | | CiviCRM is distributed in the hope that it will be useful, but | |
| 15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 17 | | See the GNU Affero General Public License for more details. | |
| 18 | | | |
| 19 | | You should have received a copy of the GNU Affero General Public | |
| 20 | | License and the CiviCRM Licensing Exception along | |
| 21 | | with this program; if not, contact CiviCRM LLC | |
| 22 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
| 23 | | GNU Affero General Public License or the licensing of CiviCRM, | |
| 24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
| 25 | +--------------------------------------------------------------------+ |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * Perform an upgrade without using the web-frontend |
| 30 | */ |
| 31 | class CRM_Upgrade_Headless { |
| 32 | |
| 33 | /** |
| 34 | * Perform an upgrade without using the web-frontend |
| 35 | * |
| 36 | * @return array, with keys: |
| 37 | * - message: string, HTML-ish blob |
| 38 | * @throws Exception |
| 39 | */ |
| 40 | function run($enablePrint = TRUE) { |
| 41 | // lets get around the time limit issue if possible for upgrades |
| 42 | if (!ini_get('safe_mode')) { |
| 43 | set_time_limit(0); |
| 44 | } |
| 45 | |
| 46 | $upgrade = new CRM_Upgrade_Form(); |
| 47 | list($currentVer, $latestVer) = $upgrade->getUpgradeVersions(); |
| 48 | |
| 49 | if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) { |
| 50 | throw new Exception($error); |
| 51 | } |
| 52 | |
| 53 | // Disable our SQL triggers |
| 54 | CRM_Core_DAO::dropTriggers(); |
| 55 | |
| 56 | // CRM-11156 |
| 57 | $preUpgradeMessage = NULL; |
| 58 | $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer); |
| 59 | |
| 60 | $postUpgradeMessageFile = CRM_Utils_File::tempnam('civicrm-post-upgrade'); |
| 61 | $queueRunner = new CRM_Queue_Runner(array( |
| 62 | 'title' => ts('CiviCRM Upgrade Tasks'), |
| 63 | 'queue' => CRM_Upgrade_Form::buildQueue($currentVer, $latestVer, $postUpgradeMessageFile), |
| 64 | )); |
| 65 | $queueResult = $queueRunner->runAll(); |
| 66 | if ($queueResult !== TRUE) { |
| 67 | $errorMessage = CRM_Core_Error::formatTextException($queueResult['exception']); |
| 68 | CRM_Core_Error::debug_log_message($errorMessage); |
| 69 | if ($enablePrint) { |
| 70 | print($errorMessage); |
| 71 | } |
| 72 | throw $queueResult['exception']; // FIXME test |
| 73 | } |
| 74 | |
| 75 | CRM_Upgrade_Form::doFinish(); |
| 76 | |
| 77 | return array( |
| 78 | 'latestVer' => $latestVer, |
| 79 | 'message' => file_get_contents($postUpgradeMessageFile), |
| 80 | ); |
| 81 | } |
| 82 | } |
| 83 | |