PageRenderTime 57ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/app/models/migrate.php

https://github.com/demonio/KuMigrate-aka-Migra-a
PHP | 219 lines | 178 code | 29 blank | 12 comment | 15 complexity | ccefd4c05619223537f9f99fcc0fa551 MD5 | raw file
  1. <?php
  2. Load::lib('files');
  3. Load::lib('ku');
  4. class Migrate
  5. {
  6. public function getPathes() # AUN SIGO PROBANDO ESTE ARRAY
  7. {
  8. return array
  9. (
  10. # 0.5 => 1.0 beta1
  11. '/apps/default' => '/app',
  12. '/apps' => '',
  13. '/app/controllers/application.php' => '/app/application.php',
  14. '/app/views/layouts' => '/app/views/templates',
  15. '/app/views/index.phtml' => '/app/views/templates/default.phtml',
  16. '/app/views/not_found.phtml' => '/app/views/errors/404.phtml',
  17. '/app/views/bienvenida.phtml' => '/app/views/pages/index.phtml',
  18. '/app/helpers' => '/app/extensions/helpers',
  19. '/app/models/base/model_base.php' => '/app/model_base.php',
  20. '/app/models/base/' => '',
  21. '/cache' => '/app/cache',
  22. '/config' => '/app/config',
  23. '/docs' => '/app/docs',
  24. '/logs' => '/app/logs',
  25. '/scripts' => '/app/scripts',
  26. '/test' => '/app/test',
  27. # 1.0 beta1 => 1.0 beta2
  28. );
  29. }
  30. public function getStrings()
  31. {
  32. return array
  33. (
  34. # application
  35. 'application' => array
  36. (
  37. 'ControllerBase' => 'ApplicationController',
  38. 'public function init(' => 'protected function initialize(',
  39. "render_view('bienvenida');" => '',
  40. ),
  41. # models
  42. 'models' => array
  43. (
  44. 'public $mode' => 'public $database',
  45. ),
  46. # Callbacks
  47. array
  48. (
  49. 'public function initialize' => 'protected function initialize',
  50. 'public function finalize' => 'protected function finalize',
  51. 'public function before_filter' => 'protected function before_filter',
  52. 'public function after_filter' => 'protected function after_filter',
  53. ),
  54. # config.ini
  55. 'boot.ini' => array
  56. (
  57. 'kumbia.' => '',
  58. 'mail.' => '',
  59. 'libchart.' => '',
  60. 'extensions' => 'libs',
  61. ),
  62. # routes.ini
  63. 'routes.ini' => array
  64. (
  65. '/ = index/index' . PHP_EOL => '',
  66. '[default]' => '[default]' . PHP_EOL . '/ = index/index',
  67. ),
  68. # Input::
  69. array
  70. (
  71. '$this->has_post(' => 'Input::hasPost(',
  72. '$this->has_get(' => 'Input::hasGet(',
  73. '$this->has_request(' => 'Input::hasRequest(',
  74. '$this->post(' => 'Input::post(',
  75. '$this->get(' => 'Input::get(',
  76. '$this->request(' => 'Input::request(',
  77. ),
  78. # View::
  79. array
  80. (
  81. '$this->cache' => 'View::cache(',
  82. '$this->render' => 'View::select(',
  83. '$this->set_response' => 'View::response(',
  84. ' content(' => ' View::content(', # ARREGLO CON ESPACIO DELANTE PARA QUE NO SEA RECURRENTE
  85. 'render_partial(' => 'View::partial(',
  86. ),
  87. # Router::
  88. array
  89. (
  90. '$this->route_to(' => 'Router::route_to(', # Se recomienda $this->route_to => Router::redirect
  91. '$this->redirect(' => 'Router::redirect(',
  92. ),
  93. # Html::
  94. array
  95. (
  96. 'img_tag(' => 'Html::img(',
  97. 'link_to(' => 'Html::link(',
  98. 'stylesheet_link_tag(' => 'Tag::css(',
  99. 'stylesheet_link_tags(' => 'Html::includeCss(',
  100. 'javascript_include_tag(' => 'Tag::js(',
  101. ),
  102. # Form::
  103. array
  104. (
  105. 'end_form_tag(' => 'Form::close(', # end_form_tag DEBE IR PRIMERO QUE form_tag O end_form_tag SERA end_Form::open
  106. 'form_tag(' => 'Form::open(',
  107. 'input_field_tag(' => 'Form::input(',
  108. 'text_field_tag(' => 'Form::text(',
  109. 'password_field_tag(' => 'Form::pass(',
  110. 'textarea_tag(' => 'Form::textarea(',
  111. 'hidden_field_tag(' => 'Form::hidden(',
  112. 'select_tag(' => 'Form::select(',
  113. 'file_field_tag(' => 'Form::file(',
  114. 'button_tag(' => 'Form::button(',
  115. 'submit_image_tag(' => 'Form::submitImage(',
  116. 'submit_tag(' => 'Form::submit(',
  117. 'checkbox_field_tag(' => 'Form::check(',
  118. 'radio_field_tag(' => 'Form::radio(',
  119. ),
  120. );
  121. }
  122. public function setPathes($dir)
  123. {
  124. $items = Files::readDir($dir, array('deny' => array('library', 'public') ) ); # VEMOS QUE HAY EN CADA DIRECTORIO
  125. if ( ! $items ) return; # NO SE PUEDE PROCESAR DIRECTORIOS VACIOS
  126. foreach ($this->getPathes() as $old => $new) # PARA CADA ITEM HAY QUE VER LOS CAMBIOS A REALIZAR
  127. {
  128. $to = $_SESSION['dad'] . $new; # RURA NUEVA COMPLETA
  129. foreach ($items as $k => $v) # VEMOS EL PUS DEL DIRECTORIO
  130. {
  131. if ( is_array($v) ) # SI ES DIRECTORIO
  132. {
  133. if ($new == '') # SI EL DESTINO ESTA VACIO SE BORRA EL ORIGEN
  134. {
  135. Files::deleteDir($k);
  136. }
  137. else if ($k == $_SESSION['dad'] . $old and $k <> $to) # SI HAY CAMBIOS
  138. {
  139. Ku::_flush("$k, $to");
  140. Files::moveDir($k, $to); # MOVEMOS EL DIRECTARIO A LA RUTA NUEVA
  141. }
  142. $this->setPathes($k); # RECURSIVIDAD
  143. }
  144. else # SI ES ARCHIVO
  145. {
  146. $from = $dir . '/' . $v;
  147. if ($from <> $_SESSION['dad'] . $old) continue;
  148. $_SESSION['result'][] = Files::moveFile($from, $to);
  149. }
  150. }
  151. }
  152. }
  153. public function setStrings($dir)
  154. {
  155. $items = Files::readDir($dir, array('deny' => array('test', 'scripts', 'public', 'logs', 'library', 'docs', 'cache') ) ); # VEMOS QUE HAY EN CADA DIRECTORIO
  156. if ( ! $items ) return; # NO SE PUEDE PROCESAR DIRECTORIOS VACIOS
  157. $found = 0;
  158. $migration = 0;
  159. $s = '';
  160. foreach ($items as $k => $v) # VEMOS EL PUS DEL DIRECTORIO
  161. {
  162. if ( is_array($v) ) $this->setStrings($k); # RECURSIVIDAD SI ES UN DIRECTORIO
  163. $file = $dir . '/' . $v;
  164. $content = Files::readFile($file); # CONTENIDO DEL ARCHIVO
  165. foreach ($this->getStrings() as $path => $changes) # PARA CADA ITEM HAY QUE VER LOS CAMBIOS A REALIZAR
  166. {
  167. foreach ($changes as $old => $new) # PARA CADA ITEM HAY QUE VER LOS CAMBIOS A REALIZAR
  168. {
  169. if ( ! preg_match('/\d+/', $path) and ! strstr($file, $path) ) break; # CONTROL DE RUTAS
  170. if ( ! strstr($content, $old) ) continue; # SI NO HAY PALABRA PARA REEMPLAZAR
  171. $found = 1; # SE HA ENCONTRADO ALGO QUE CAMBIAR
  172. $s .= substr_count($content, $old) . ' <em>' . $old . ' => ' . $new . '</em><br />'; # SE CUENTA EL NUMERO DE SUSTITUCIONES
  173. $content = str_replace(array("\r\n", "\r", "\n"), '[[:eol:]]', $content); # HUMM
  174. $content = str_replace('[[:eol:]]', PHP_EOL, $content); # HUMM 2
  175. $content = str_replace($old, $new, $content);
  176. }
  177. }
  178. if ($found) # SI SE ENCONTRARON CAMBIOS SE ACTUALIZA EL CONTENIDO
  179. {
  180. Files::updateFile($file, $content);
  181. $found = 0;
  182. $migration = 1;
  183. $_SESSION['result'][] = $s . $file . ' <strong>actualizado!</strong>';
  184. $s = '';
  185. }
  186. }
  187. if ( ! $migration ) $_SESSION['result'][] = '<strong>No hubo cambios en</strong> ' . $dir;
  188. }
  189. }
  190. ?>