Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ( ! fopen('application/config/config.php', 'r'))
- {
- die("Please place this script at the same level as your application directory.\n\n");
- }
- fwrite(STDOUT, "Are you sure you want to migrate the current application from pre 3.0 to 2.3? (Type 'y' to continue)\n");
- $continue = fgetc(STDIN);
- if ($continue != strtolower('y'))
- {
- fwrite(STDOUT, "Bye!\n\n");
- }
- else
- {
- define('DOCROOT', getcwd().DIRECTORY_SEPARATOR);
- define('APPPATH', str_replace('\\', '/', realpath('application')).'/');
- // include_once 'application/config/config.php';
- // ----------------------------------------
- fwrite(STDOUT, "Starting migration, please wait ...\n\n");
- // ----------------------------------------
- // Backup
- // ----------------------------------------
- fwrite(STDOUT, "Backing up your application folder ...\n\n");
- exec('mkdir application.pre30');
- exec('cp -R application/* application.pre30');
- // ----------------------------------------
- // Migration - File structure
- // ----------------------------------------
- fwrite(STDOUT, "Creating new file structure ...\n\n");
- exec('mkdir application/controllers');
- exec('mkdir application/helpers');
- exec('mkdir application/libraries');
- exec('mkdir application/models');
- // ----------------------------------------
- // Migration - Moving files
- // ----------------------------------------
- fwrite(STDOUT, "Moving files ...\n\n");
- exec('mv application/classes/controller/* application/controllers');
- exec('mv application/classes/model/* application/models');
- if ($handle = opendir(APPPATH.'classes/'))
- {
- while (false !== ($file = readdir($handle)))
- {
- if ($file != "." && $file != ".." && $file != '.DS_Store' && substr($file, -3) == 'php')
- {
- $filename = $file;
- if (substr($file, 0, 3) == 'MY_')
- {
- $filename = substr($file, 3);
- }
- $type = ($filename[0] < 'a') ? 'helpers' : 'libraries';
- rename("application/classes/$file", "application/$type/$file");
- }
- }
- closedir($handle);
- }
- exec('rm -rf application/classes');
- // ----------------------------------------
- // Migration - Controllers
- // ----------------------------------------
- fwrite(STDOUT, "Renaming controllers ...\n\n");
- if ($handle = opendir(APPPATH.'controllers/'))
- {
- while (false !== ($file = readdir($handle)))
- {
- if ($file != "." && $file != ".." && $file != '.DS_Store' && substr($file, -3) == 'php')
- {
- $data = file_get_contents(APPPATH.'controllers/'.$file);
- $data = preg_replace('/Controller_(\w*)/m', '$1_Controller', $data);
- $data = preg_replace('/Model_(\w*)/m', '$1', $data);
- file_put_contents(APPPATH.'controllers/'.$file, $data);
- }
- }
- closedir($handle);
- }
- // ----------------------------------------
- // Migration - Models
- // ----------------------------------------
- fwrite(STDOUT, "Renaming models ...\n\n");
- if ($handle = opendir(APPPATH.'models/'))
- {
- while (false !== ($file = readdir($handle)))
- {
- if ($file != "." && $file != ".." && $file != '.DS_Store' && substr($file, -3) == 'php')
- {
- $data = file_get_contents(APPPATH.'models/'.$file);
- $data = preg_replace('/Model_(\w*)/m', '$1_Model', $data);
- file_put_contents(APPPATH.'models/'.$file, $data);
- }
- }
- closedir($handle);
- }
- // ----------------------------------------
- fwrite(STDOUT, "Migration completed!\n\n");
- }
- exit(0);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement