Advertisement
Guest User

Fred Wu

a guest
Dec 21st, 2008
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.44 KB | None | 0 0
  1. <?php
  2.  
  3. if ( ! fopen('application/config/config.php', 'r'))
  4. {
  5.     die("Please place this script at the same level as your application directory.\n\n");
  6. }
  7.  
  8. fwrite(STDOUT, "Are you sure you want to migrate the current application from pre 3.0 to 2.3? (Type 'y' to continue)\n");
  9.  
  10. $continue = fgetc(STDIN);
  11.  
  12. if ($continue != strtolower('y'))
  13. {
  14.     fwrite(STDOUT, "Bye!\n\n");
  15. }
  16. else
  17. {
  18.     define('DOCROOT', getcwd().DIRECTORY_SEPARATOR);
  19.     define('APPPATH', str_replace('\\', '/', realpath('application')).'/');
  20.     // include_once 'application/config/config.php';
  21.    
  22.     // ----------------------------------------
  23.    
  24.     fwrite(STDOUT, "Starting migration, please wait ...\n\n");
  25.    
  26.     // ----------------------------------------
  27.     // Backup
  28.     // ----------------------------------------
  29.    
  30.     fwrite(STDOUT, "Backing up your application folder ...\n\n");
  31.    
  32.     exec('mkdir application.pre30');
  33.     exec('cp -R application/* application.pre30');
  34.    
  35.     // ----------------------------------------
  36.     // Migration - File structure
  37.     // ----------------------------------------
  38.    
  39.     fwrite(STDOUT, "Creating new file structure ...\n\n");
  40.    
  41.     exec('mkdir application/controllers');
  42.     exec('mkdir application/helpers');
  43.     exec('mkdir application/libraries');
  44.     exec('mkdir application/models');
  45.    
  46.     // ----------------------------------------
  47.     // Migration - Moving files
  48.     // ----------------------------------------
  49.    
  50.     fwrite(STDOUT, "Moving files ...\n\n");
  51.    
  52.     exec('mv application/classes/controller/* application/controllers');
  53.     exec('mv application/classes/model/* application/models');
  54.    
  55.     if ($handle = opendir(APPPATH.'classes/'))
  56.     {
  57.         while (false !== ($file = readdir($handle)))
  58.         {
  59.             if ($file != "." && $file != ".." && $file != '.DS_Store' && substr($file, -3) == 'php')
  60.             {
  61.                 $filename = $file;
  62.                 if (substr($file, 0, 3) == 'MY_')
  63.                 {
  64.                     $filename = substr($file, 3);
  65.                 }
  66.                
  67.                 $type = ($filename[0] < 'a') ? 'helpers' : 'libraries';
  68.                
  69.                 rename("application/classes/$file", "application/$type/$file");
  70.             }
  71.         }
  72.         closedir($handle);
  73.     }
  74.    
  75.     exec('rm -rf application/classes');
  76.    
  77.     // ----------------------------------------
  78.     // Migration - Controllers
  79.     // ----------------------------------------
  80.    
  81.     fwrite(STDOUT, "Renaming controllers ...\n\n");
  82.    
  83.     if ($handle = opendir(APPPATH.'controllers/'))
  84.     {
  85.         while (false !== ($file = readdir($handle)))
  86.         {
  87.             if ($file != "." && $file != ".." && $file != '.DS_Store' && substr($file, -3) == 'php')
  88.             {
  89.                 $data = file_get_contents(APPPATH.'controllers/'.$file);
  90.  
  91.                 $data = preg_replace('/Controller_(\w*)/m', '$1_Controller', $data);
  92.                 $data = preg_replace('/Model_(\w*)/m', '$1', $data);
  93.                
  94.                 file_put_contents(APPPATH.'controllers/'.$file, $data);
  95.             }
  96.         }
  97.         closedir($handle);
  98.     }
  99.    
  100.     // ----------------------------------------
  101.     // Migration - Models
  102.     // ----------------------------------------
  103.    
  104.     fwrite(STDOUT, "Renaming models ...\n\n");
  105.    
  106.     if ($handle = opendir(APPPATH.'models/'))
  107.     {
  108.         while (false !== ($file = readdir($handle)))
  109.         {
  110.             if ($file != "." && $file != ".." && $file != '.DS_Store' && substr($file, -3) == 'php')
  111.             {
  112.                 $data = file_get_contents(APPPATH.'models/'.$file);
  113.  
  114.                 $data = preg_replace('/Model_(\w*)/m', '$1_Model', $data);
  115.                
  116.                 file_put_contents(APPPATH.'models/'.$file, $data);
  117.             }
  118.         }
  119.         closedir($handle);
  120.     }
  121.    
  122.     // ----------------------------------------
  123.    
  124.     fwrite(STDOUT, "Migration completed!\n\n");
  125. }
  126.  
  127. exit(0);
  128.  
  129. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement