Elgg\UpgradeService::run PHP Method

run() public method

Run the upgrade process
public run ( ) : array
return array $result Associative array containing possible errors
    public function run()
    {
        $result = array('failure' => false, 'reason' => '');
        // prevent someone from running the upgrade script in parallel (see #4643)
        if (!$this->mutex->lock('upgrade')) {
            $result['failure'] = true;
            $result['reason'] = $this->translator->translate('upgrade:locked');
            return $result;
        }
        // disable the system log for upgrades to avoid exceptions when the schema changes.
        $this->events->unregisterHandler('log', 'systemlog', 'system_log_default_logger');
        $this->events->unregisterHandler('all', 'all', 'system_log_listener');
        // turn off time limit
        set_time_limit(0);
        if ($this->getUnprocessedUpgrades()) {
            $this->processUpgrades();
        }
        $this->events->trigger('upgrade', 'system', null);
        elgg_flush_caches();
        $this->mutex->unlock('upgrade');
        return $result;
    }

Usage Example

Beispiel #1
0
 /**
  * This will test an upgrade run, just like calling /upgrade.php
  */
 public function testUpgradeRun()
 {
     // marked as incomplete because $CONFIG isn't available
     $this->markTestIncomplete();
     try {
         // running database upgrades can through exceptions
         $result = $this->service->run();
         $this->assertTrue(is_array($result));
         $this->assertArrayHasKey("failure", $result);
         $this->assertFalse($result["failure"]);
     } catch (Exception $e) {
         $this->fail($e->getMessage());
     }
 }