Created
August 2, 2012 23:18
-
-
Save ynh-zz/3241814 to your computer and use it in GitHub Desktop.
Update in beforeFilter() AppController
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Check if the last db update was installed | |
if (!file_exists(CONFIGS . 'update' . $this->lastV . '.yml')) { | |
@set_time_limit(60 * 60); | |
@App::import('Model', 'ConnectionManager'); | |
$db = ConnectionManager::getDataSource('default'); | |
//Loop across all the version numbers | |
for ($index = 1; $index - 1 < $this->lastV; $index++) { | |
//Was the version installed | |
if (!file_exists(CONFIGS . 'update' . $index . '.yml')) { | |
if (file_exists(ROOT . DS . APP_DIR . DS . "updates" . DS . 'update' . $index . '.sql')) { | |
//load app/updates/update{version_number}.sql | |
$statements = file_get_contents(ROOT . DS . APP_DIR . DS . "updates" . DS . 'update' . $index . '.sql'); | |
$statements = explode(";\n", $statements); | |
foreach ($statements as $statement) { | |
if (trim($statement) != '') { | |
$db->query($statement); | |
} | |
} | |
} | |
Cache::clear(); | |
file_put_contents(CONFIGS . 'update' . $index . '.yml', "-"); | |
} | |
} | |
//Clean Cache | |
$settings = array( | |
'view_cache_path' => ROOT . DS . APP . 'tmp' . DS . 'cache' . DS . 'views', | |
'std_cache_paths' => array( | |
ROOT . DS . APP_DIR . DS . 'tmp' . DS . 'cache' . DS . 'models', | |
ROOT . DS . APP_DIR . DS . 'tmp' . DS . 'cache' . DS . 'persistent', | |
) | |
); | |
$paths = $settings['std_cache_paths']; | |
foreach ($paths as $path) { | |
$folder = new Folder($path); | |
$contents = $folder->read(); | |
foreach ($contents[1] as $file) { | |
@unlink($path . DS . $file); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment