Skip to content

Commit

Permalink
SQL update
Browse files Browse the repository at this point in the history
  • Loading branch information
mattimaards committed Nov 26, 2012
1 parent ec1d79a commit 1112d6b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
19 changes: 13 additions & 6 deletions classes/ezupgrade.php
Expand Up @@ -504,36 +504,39 @@ function getDBDetailsFromINI($siteIniFile)

function getSiteIniFiles()
{
$siteIniList = ezcBaseFile::findRecursive( $this->getNewDistroPathName() . "settings", array( '@site\.ini@' ) );
$siteIniList = ezcBaseFile::findRecursive( $this->getNewDistroFolderName() . "settings", array( '@site\.ini@' ) );

$result = array();
foreach($siteIniList as $siteIniFilePath)
{
$parts = explode($this->getNewDistroPathName(), $siteIniFilePath);
$parts = explode($this->getNewDistroFolderName(), $siteIniFilePath);

// ignore the default site.ini and any temp INI files
if($parts[1] != 'settings/site.ini' AND $parts[1] != '/settings/site.ini' AND !strstr($siteIniFilePath, '~') AND !strstr($siteIniFilePath, '.LCK') AND !strpos($parts[1], '.svn'))
{
$result[] = $parts[1];
}
}

return $result;
}
function updateDBConnections()
{
foreach( $this->getSiteIniFiles() as $iniFile )
{
echo "Processing $iniFile\n";
// get instance of current ini file
$ini = $this->iniInstance($iniFile);

$ini = $this->iniInstance($iniFile, $basePath=$this->getNewDistroFolderName());


$oldDBName = false;

// get current db name
if ( $ini->hasVariable( 'DatabaseSettings', 'Database' ) )
{
$oldDBName = $ini->variable('DatabaseSettings', 'Database');
}

// provided that the INI file has a database name set
if($oldDBName !== false )
{
Expand All @@ -545,7 +548,7 @@ function updateDBConnections()
$ini->setVariable('DatabaseSettings', 'Database', $this->dbhandler->createNewDBName($oldDBName));

// save changes in ini file
if(!$ini->save() )
if(!$ini->save())
{
$this->checkpoint('updateDBConnections()', 'Please change your database name in ' . $iniFile, true);
}
Expand All @@ -556,6 +559,10 @@ function updateDBConnections()
}

}
else
{
$this->log("Could not find current database info\n");
}
}
$this->log( "end of updateDBConnections()\n" );
}
Expand Down
42 changes: 32 additions & 10 deletions classes/upgradefunctions.php
Expand Up @@ -22,19 +22,27 @@ function upgradeFunctions(&$upgrade)
$this->upgrade = $upgrade;
}

function runScript($script, $version=5)
function runScript($script, $version=5, $root=null)
{
$phpCli = $this->upgrade->getPathToPHP( $version );
$siteAccessList = $this->upgrade->upgradeData['siteaccess_list'];
if ( is_array( $siteAccessList ) )
{
foreach( $siteAccessList as $siteaccess )
{
$this->upgrade->log("Running script $script -s" . $siteaccess);
$this->upgrade->log("Running script $script -s" . $siteaccess . "\n");

$this->upgrade->checkpoint( 'Running script: ' . $script );

exec("cd " . $this->upgrade->getNewDistroFolderName() . ";".$phpCli." " . $script . " -s" . $siteaccess);
$distroDir = $this->upgrade->getNewDistroFolderName();
if($root)
{
$distroDir = $root;
exec("cd " . $distroDir . ";".$phpCli." " . $script);
}
else
{
exec("cd " . $distroDir . ";".$phpCli." " . $script . " -s" . $siteaccess);
}
$this->upgrade->log("OK\n", 'ok');
}
}
Expand Down Expand Up @@ -70,6 +78,7 @@ function updateDB($sql, $useBasePath = true)

// for each database
$dbList = $this->upgrade->fetchDbList();

foreach($dbList as $db)
{
$newDBName = $this->upgrade->dbhandler->createNewDBName( $db['Database']);
Expand All @@ -82,13 +91,12 @@ function updateDBForVersion( $version )
{
$versionStep = explode('.', $version );
$sqlFile = 'sql/' . $versionStep[0] . '.' . $versionStep[1] . '/' . $version .'.sql';

// 5.0.0 is still unstable
if(version_compare($version, '5.0.0') == 0) {
$sqlFiles = glob($this->upgrade->getNewDistroFolderName() . 'update/database/5.0/unstable/*.sql');
if(version_compare($version, '5.0.0', '>=')) {
$sqlFiles = glob($this->upgrade->getNewDistroFolderName() . 'update/database/mysql/' . $versionStep[0] . '.' . $versionStep[1] . '/unstable/*.sql');
sort($sqlFiles);
foreach($sqlFiles as $file) {
$this->updateDB($file);
$this->updateDB('update/database/mysql/' . $versionStep[0] . '.' . $versionStep[1] . '/unstable/' . basename($file));
}
} else {
$this->updateDB( $sqlFile, false );
Expand Down Expand Up @@ -385,14 +393,28 @@ public function execute500Scripts()
'bin/php/ezpgenerateautoloads.php --extension')
as $scriptFile)
{
exec('php ' . $this->upgrade->getNewDistroFolderName() . $scriptFile);
$this->runScript($scriptFile, 5, $this->upgrade->getNewDistroFolderName());
}
}


public function generateYmlConfigAndSymlink()
{

foreach(array('dev', 'prod') as $env)
{
$cmd = sprintf("ezpublish/console ezpublish:configure --env=%s '%s' '%s'",
$env, addslashes('site'), addslashes('site_admin'));

$this->runScript($cmd, 5, $this->upgrade->getNewDistroRoot());
}

// Generate symlinks for assets (var)
foreach(array( 'ezpublish/console assets:install --symlink web',
'ezpublish/console ezpublish:legacy:assets_install --symlink web')
as $scriptFile)
{
$this->runScript($scriptFile, 5, $this->upgrade->getNewDistroRoot());
}
}


Expand Down
1 change: 1 addition & 0 deletions settings/ezupgrade.ini
Expand Up @@ -176,6 +176,7 @@ Requirements[]=PHP5
UpgradeFunctions[]=createRequiredDirectoriesFor500
UpgradeFunctions[]=updateDBForVersion
UpgradeFunctions[]=execute500Scripts
UpgradeFunctions[]=generateYmlConfigAndSymlink
UpgradeFunctions[]=generateAutoLoads
UpgradeFunctions[]=generateAutoLoadsKernel
UpgradeFunctions[]=clearCache
Expand Down

0 comments on commit 1112d6b

Please sign in to comment.