Skip to content

Commit

Permalink
Merge pull request #8201 from juho-jaakkola/upgrade_cleanup
Browse files Browse the repository at this point in the history
chore(upgrades): removes support for upgrading Elgg from version 1.7
  • Loading branch information
juho-jaakkola committed Apr 15, 2015
2 parents 0a5abd6 + 21a6efd commit 0932a1f
Show file tree
Hide file tree
Showing 28 changed files with 6 additions and 469 deletions.
3 changes: 0 additions & 3 deletions docs/design/database.rst
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,3 @@ the metadata and annotations tables.

This is to avoid duplicating strings, saving space and making database
lookups more efficient.

Core developers will place schema upgrades in
``/engine/schema/upgrades/*``.
141 changes: 6 additions & 135 deletions engine/classes/Elgg/UpgradeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class UpgradeService {

/**
* Global Elgg configuration
*
*
* @var \stdClass
*/
private $CONFIG;
Expand Down Expand Up @@ -80,14 +80,6 @@ protected function upgradeCode($version, $quiet = false) {
$upgrade_path = _elgg_services()->config->get('path') . 'engine/lib/upgrades/';
$processed_upgrades = $this->getProcessedUpgrades();

// upgrading from 1.7 to 1.8. Need to bootstrap.
if (!$processed_upgrades) {
$this->bootstrap17to18();

// grab accurate processed upgrades
$processed_upgrades = $this->getProcessedUpgrades();
}

$upgrade_files = $this->getUpgradeFiles($upgrade_path);

if ($upgrade_files === false) {
Expand All @@ -109,7 +101,7 @@ protected function upgradeCode($version, $quiet = false) {
// added to the database.
continue;
}

// hide all errors.
if ($quiet) {
// hide include errors as well as any exceptions that might happen
Expand Down Expand Up @@ -270,17 +262,7 @@ protected function processUpgrades() {

$dbversion = (int) _elgg_services()->datalist->get('version');

// No version number? Oh snap...this is an upgrade from a clean installation < 1.7.
// Run all upgrades without error reporting and hope for the best.
// See https://github.com/elgg/elgg/issues/1432 for more.
$quiet = !$dbversion;

// Note: Database upgrades are deprecated as of 1.8. Use code upgrades. See #1433
if ($this->dbUpgrade($dbversion, '', $quiet)) {
system_message(_elgg_services()->translator->translate('upgrade:db'));
}

if ($this->upgradeCode($dbversion, $quiet)) {
if ($this->upgradeCode($dbversion)) {
system_message(_elgg_services()->translator->translate('upgrade:core'));

// Now we trigger an event to give the option for plugins to do something
Expand All @@ -296,53 +278,13 @@ protected function processUpgrades() {
return false;
}

/**
* Boot straps into 1.8 upgrade system from 1.7
*
* This runs all the 1.7 upgrades, then sets the processed_upgrades to all existing 1.7 upgrades.
* Control is then passed back to the main upgrade function which detects and runs the
* 1.8 upgrades, regardless of filename convention.
*
* @return bool
*/
protected function bootstrap17to18() {
$db_version = (int) _elgg_services()->datalist->get('version');

// the 1.8 upgrades before the upgrade system change that are interspersed with 1.7 upgrades.
$upgrades_18 = array(
'2010111501.php',
'2010121601.php',
'2010121602.php',
'2010121701.php',
'2010123101.php',
'2011010101.php',
);

$upgrade_files = $this->getUpgradeFiles();
$processed_upgrades = array();

foreach ($upgrade_files as $upgrade_file) {
// ignore if not in 1.7 format or if it's a 1.8 upgrade
if (in_array($upgrade_file, $upgrades_18) || !preg_match("/[0-9]{10}\.php/", $upgrade_file)) {
continue;
}

$upgrade_version = $this->getUpgradeFileVersion($upgrade_file);

// this has already been run in a previous 1.7.X -> 1.7.X upgrade
if ($upgrade_version < $db_version) {
$this->setProcessedUpgrade($upgrade_file);
}
}
}

/**
* Creates a table {prefix}upgrade_lock that is used as a mutex for upgrades.
*
* @return bool
*/
protected function getUpgradeMutex() {


if (!$this->isUpgradeLocked()) {
// lock it
Expand All @@ -361,7 +303,7 @@ protected function getUpgradeMutex() {
* @return void
*/
public function releaseUpgradeMutex() {

_elgg_services()->db->deleteData("drop table {$this->CONFIG->dbprefix}upgrade_lock");
_elgg_services()->logger->notice('Upgrade unlocked.');
}
Expand All @@ -372,82 +314,11 @@ public function releaseUpgradeMutex() {
* @return bool
*/
public function isUpgradeLocked() {


$is_locked = count(_elgg_services()->db->getData("SHOW TABLES LIKE '{$this->CONFIG->dbprefix}upgrade_lock'"));

return (bool)$is_locked;
}

/**
* ***************************************************************************
* NOTE: If this is ever removed from Elgg, sites lose the ability to upgrade
* from 1.7.x and earlier to the latest version of Elgg without upgrading to
* 1.8 first.
* ***************************************************************************
*
* Upgrade the database schema in an ordered sequence.
*
* Executes all upgrade files in elgg/engine/schema/upgrades/ in sequential order.
* Upgrade files must be in the standard Elgg release format of YYYYMMDDII.sql
* where II is an incrementor starting from 01.
*
* Files that are < $version will be ignored.
*
* @param int $version The version you are upgrading from in the format YYYYMMDDII.
* @param string $fromdir Optional directory to load upgrades from. default: engine/schema/upgrades/
* @param bool $quiet If true, suppress all error messages. Only use for the upgrade from <=1.6.
*
* @return int The number of upgrades run.
* @deprecated 1.8 Use PHP upgrades for sql changes.
*/
protected function dbUpgrade($version, $fromdir = "", $quiet = false) {


$version = (int) $version;

if (!$fromdir) {
$fromdir = $this->CONFIG->path . 'engine/schema/upgrades/';
}

$i = 0;

if ($handle = opendir($fromdir)) {
$sqlupgrades = array();

while ($sqlfile = readdir($handle)) {
if (!is_dir($fromdir . $sqlfile)) {
if (preg_match('/^([0-9]{10})\.(sql)$/', $sqlfile, $matches)) {
$sql_version = (int) $matches[1];
if ($sql_version > $version) {
$sqlupgrades[] = $sqlfile;
}
}
}
}

asort($sqlupgrades);

if (sizeof($sqlupgrades) > 0) {
foreach ($sqlupgrades as $sqlfile) {

// hide all errors.
if ($quiet) {
try {
_elgg_services()->db->runSqlScript($fromdir . $sqlfile);
} catch (\DatabaseException $e) {
error_log($e->getmessage());
}
} else {
_elgg_services()->db->runSqlScript($fromdir . $sqlfile);
}
$i++;
}
}
}

return $i;
}

}

100 changes: 0 additions & 100 deletions engine/schema/upgrades/2008092301.sql

This file was deleted.

14 changes: 0 additions & 14 deletions engine/schema/upgrades/2008100601.sql

This file was deleted.

11 changes: 0 additions & 11 deletions engine/schema/upgrades/2008101601.sql

This file was deleted.

7 changes: 0 additions & 7 deletions engine/schema/upgrades/2008101701.sql

This file was deleted.

9 changes: 0 additions & 9 deletions engine/schema/upgrades/2008102101.sql

This file was deleted.

17 changes: 0 additions & 17 deletions engine/schema/upgrades/2008110301.sql

This file was deleted.

3 changes: 0 additions & 3 deletions engine/schema/upgrades/2008110601.sql

This file was deleted.

8 changes: 0 additions & 8 deletions engine/schema/upgrades/2008111901.sql

This file was deleted.

0 comments on commit 0932a1f

Please sign in to comment.