37 public function run() {
44 if (!$this->getUpgradeMutex()) {
51 _elgg_services()->events->unregisterHandler(
'log',
'systemlog',
'system_log_default_logger');
52 _elgg_services()->events->unregisterHandler(
'all',
'all',
'system_log_listener');
57 if ($this->getUnprocessedUpgrades()) {
58 $this->processUpgrades();
65 $this->releaseUpgradeMutex();
80 $upgrade_path =
_elgg_services()->config->get(
'path') .
'engine/lib/upgrades/';
81 $processed_upgrades = $this->getProcessedUpgrades();
84 if (!$processed_upgrades) {
85 $this->bootstrap17to18();
88 $processed_upgrades = $this->getProcessedUpgrades();
91 $upgrade_files = $this->getUpgradeFiles($upgrade_path);
93 if ($upgrade_files ===
false) {
97 $upgrades = $this->getUnprocessedUpgrades($upgrade_files, $processed_upgrades);
103 $upgrade_version = $this->getUpgradeFileVersion($upgrade);
117 if (!@self::includeCode(
"$upgrade_path/$upgrade")) {
119 error_log(
"Could not include $upgrade_path/$upgrade");
121 }
catch (\Exception
$e) {
123 error_log(
$e->getMessage());
126 if (!self::includeCode(
"$upgrade_path/$upgrade")) {
128 error_log(
"Could not include $upgrade_path/$upgrade");
140 $this->setProcessedUpgrade($upgrade);
159 return include $file;
170 $processed_upgrades = $this->getProcessedUpgrades();
171 $processed_upgrades[] = $upgrade;
172 $processed_upgrades = array_unique($processed_upgrades);
173 return _elgg_services()->datalist->set(
'processed_upgrades', serialize($processed_upgrades));
184 return $unserialized;
195 preg_match(
'/^([0-9]{10})([\.a-z0-9-_]+)?\.(php)$/i',
$filename, $matches);
197 if (isset($matches[1])) {
198 return (
int) $matches[1];
211 if (!$upgrade_path) {
212 $upgrade_path =
_elgg_services()->config->get(
'path') .
'engine/lib/upgrades/';
215 $handle = opendir($upgrade_path);
221 $upgrade_files = array();
223 while ($upgrade_file = readdir($handle)) {
225 if (is_dir($upgrade_path .
'$upgrade_file')) {
228 $upgrade_version = $this->getUpgradeFileVersion($upgrade_file);
229 if (!$upgrade_version) {
232 $upgrade_files[] = $upgrade_file;
235 sort($upgrade_files);
237 return $upgrade_files;
249 if ($upgrade_files ===
null) {
250 $upgrade_files = $this->getUpgradeFiles();
253 if ($processed_upgrades ===
null) {
254 $processed_upgrades = unserialize(
_elgg_services()->datalist->get(
'processed_upgrades'));
255 if (!is_array($processed_upgrades)) {
256 $processed_upgrades = array();
260 $unprocessed = array_diff($upgrade_files, $processed_upgrades);
276 $quiet = !$dbversion;
279 if ($this->dbUpgrade($dbversion,
'', $quiet)) {
283 if ($this->upgradeCode($dbversion, $quiet)) {
287 $upgrade_details = new \stdClass;
288 $upgrade_details->from = $dbversion;
291 _elgg_services()->events->trigger(
'upgrade',
'upgrade', $upgrade_details);
312 $upgrades_18 = array(
321 $upgrade_files = $this->getUpgradeFiles();
322 $processed_upgrades = array();
324 foreach ($upgrade_files as $upgrade_file) {
326 if (in_array($upgrade_file, $upgrades_18) || !preg_match(
"/[0-9]{10}\.php/", $upgrade_file)) {
330 $upgrade_version = $this->getUpgradeFileVersion($upgrade_file);
333 if ($upgrade_version < $db_version) {
334 $this->setProcessedUpgrade($upgrade_file);
347 if (!$this->isUpgradeLocked()) {
349 _elgg_services()->db->insertData(
"create table {$this->CONFIG->dbprefix}upgrade_lock (id INT)");
354 _elgg_services()->logger->warn(
'Cannot lock for upgrade: already locked');
365 _elgg_services()->db->deleteData(
"drop table {$this->CONFIG->dbprefix}upgrade_lock");
410 $fromdir = $this->CONFIG->path .
'engine/schema/upgrades/';
415 if ($handle = opendir($fromdir)) {
416 $sqlupgrades = array();
418 while ($sqlfile = readdir($handle)) {
419 if (!is_dir($fromdir . $sqlfile)) {
420 if (preg_match(
'/^([0-9]{10})\.(sql)$/', $sqlfile, $matches)) {
421 $sql_version = (int) $matches[1];
423 $sqlupgrades[] = $sqlfile;
431 if (
sizeof($sqlupgrades) > 0) {
432 foreach ($sqlupgrades as $sqlfile) {
439 error_log(
$e->getmessage());
elgg_reset_system_cache()
Reset the system cache by deleting the caches.
elgg_invalidate_simplecache()
Deletes all cached views in the simplecache and sets the lastcache and lastupdate time to 0 for every...
run()
Run the upgrade process.
__construct()
Constructor.
getUpgradeMutex()
Creates a table {prefix}upgrade_lock that is used as a mutex for upgrades.
processUpgrades()
Upgrades Elgg Database and code.
static includeCode($file)
PHP include a file with a very limited scope.
getProcessedUpgrades()
Gets a list of processes upgrades.
isUpgradeLocked()
Checks if upgrade is locked.
getUpgradeFiles($upgrade_path=null)
Returns a list of upgrade files relative to the $upgrade_path dir.
dbUpgrade($version, $fromdir="", $quiet=false)
upgradeCode($version, $quiet=false)
Run any php upgrade scripts which are required.
releaseUpgradeMutex()
Unlocks upgrade.
bootstrap17to18()
Boot straps into 1.8 upgrade system from 1.7.
getUnprocessedUpgrades($upgrade_files=null, $processed_upgrades=null)
Checks if any upgrades need to be run.
getUpgradeFileVersion($filename)
Returns the version of the upgrade filename.
setProcessedUpgrade($upgrade)
Saves a processed upgrade to a dataset.
sanitise_filepath($path, $append_slash=true)
Sanitise file paths ensuring that they begin and end with slashes etc.
system_message($message)
Display a system message on next page load.
elgg_get_version($human_readable=false)
Get the current Elgg version information.
$upgrades
Lists pending upgrades.