UpgradeShell.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. <?php
  2. /**
  3. * Upgrade Shell
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @package Cake.Console.Command
  16. * @since CakePHP(tm) v 2.0
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('Folder', 'Utility');
  20. /**
  21. * A shell class to help developers upgrade applications to CakePHP 2.0
  22. *
  23. * @package Cake.Console.Command
  24. */
  25. class UpgradeShell extends Shell {
  26. /**
  27. * Files
  28. *
  29. * @var array
  30. */
  31. protected $_files = array();
  32. /**
  33. * Paths
  34. *
  35. * @var array
  36. */
  37. protected $_paths = array();
  38. /**
  39. * Map
  40. *
  41. * @var array
  42. */
  43. protected $_map = array(
  44. 'Controller' => 'Controller',
  45. 'Component' => 'Controller/Component',
  46. 'Model' => 'Model',
  47. 'Behavior' => 'Model/Behavior',
  48. 'Datasource' => 'Model/Datasource',
  49. 'Dbo' => 'Model/Datasource/Database',
  50. 'View' => 'View',
  51. 'Helper' => 'View/Helper',
  52. 'Shell' => 'Console/Command',
  53. 'Task' => 'Console/Command/Task',
  54. 'Case' => 'Test/Case',
  55. 'Fixture' => 'Test/Fixture',
  56. 'Error' => 'Lib/Error',
  57. );
  58. /**
  59. * Shell startup, prints info message about dry run.
  60. *
  61. * @return void
  62. */
  63. public function startup() {
  64. parent::startup();
  65. if ($this->params['dry-run']) {
  66. $this->out(__d('cake_console', '<warning>Dry-run mode enabled!</warning>'), 1, Shell::QUIET);
  67. }
  68. if ($this->params['git'] && !is_dir('.git')) {
  69. $this->out(__d('cake_console', '<warning>No git repository detected!</warning>'), 1, Shell::QUIET);
  70. }
  71. }
  72. /**
  73. * Run all upgrade steps one at a time
  74. *
  75. * @return void
  76. */
  77. public function all() {
  78. foreach($this->OptionParser->subcommands() as $command) {
  79. $name = $command->name();
  80. if ($name === 'all') {
  81. continue;
  82. }
  83. $this->out(__d('cake_console', 'Running %s', $name));
  84. $this->$name();
  85. }
  86. }
  87. /**
  88. * Update tests.
  89. *
  90. * - Update tests class names to FooTest rather than FooTestCase.
  91. *
  92. * @return void
  93. */
  94. public function tests() {
  95. $this->_paths = array(APP . 'tests' . DS);
  96. if (!empty($this->params['plugin'])) {
  97. $this->_paths = array(App::pluginPath($this->params['plugin']) . 'tests' . DS);
  98. }
  99. $patterns = array(
  100. array(
  101. '*TestCase extends CakeTestCase to *Test extends CakeTestCase',
  102. '/([a-zA-Z]*Test)Case extends CakeTestCase/',
  103. '\1 extends CakeTestCase'
  104. ),
  105. );
  106. $this->_filesRegexpUpdate($patterns);
  107. }
  108. /**
  109. * Move files and folders to their new homes
  110. *
  111. * Moves folders containing files which cannot necessarily be auto-detected (libs and templates)
  112. * and then looks for all php files except vendors, and moves them to where Cake 2.0 expects
  113. * to find them.
  114. *
  115. * @return void
  116. */
  117. public function locations() {
  118. $cwd = getcwd();
  119. if (!empty($this->params['plugin'])) {
  120. chdir(App::pluginPath($this->params['plugin']));
  121. }
  122. if (is_dir('plugins')) {
  123. $Folder = new Folder('plugins');
  124. list($plugins) = $Folder->read();
  125. foreach($plugins as $plugin) {
  126. chdir($cwd . DS . 'plugins' . DS . $plugin);
  127. $this->locations();
  128. }
  129. $this->_files = array();
  130. chdir($cwd);
  131. }
  132. $moves = array(
  133. 'config' => 'Config',
  134. 'Config' . DS . 'schema' => 'Config' . DS . 'Schema',
  135. 'libs' => 'Lib',
  136. 'tests' => 'Test',
  137. 'views' => 'View',
  138. 'models' => 'Model',
  139. 'Model' . DS . 'behaviors' => 'Model' . DS . 'Behavior',
  140. 'Model' . DS . 'datasources' => 'Model' . DS . 'Datasource',
  141. 'Test' . DS . 'cases' => 'Test' . DS . 'Case',
  142. 'Test' . DS . 'fixtures' => 'Test' . DS . 'Fixture',
  143. 'vendors' . DS . 'shells' . DS . 'templates' => 'Console' . DS . 'Templates',
  144. );
  145. foreach($moves as $old => $new) {
  146. if (is_dir($old)) {
  147. $this->out(__d('cake_console', 'Moving %s to %s', $old, $new));
  148. if (!$this->params['dry-run']) {
  149. if ($this->params['git']) {
  150. exec('git mv -f ' . escapeshellarg($old) . ' ' . escapeshellarg($old . '__'));
  151. exec('git mv -f ' . escapeshellarg($old . '__') . ' ' . escapeshellarg($new));
  152. } else {
  153. $Folder = new Folder($old);
  154. $Folder->move($new);
  155. }
  156. }
  157. }
  158. }
  159. $this->_moveViewFiles();
  160. $sourceDirs = array(
  161. '.' => array('recursive' => false),
  162. 'Console',
  163. 'controllers',
  164. 'Controller',
  165. 'Lib' => array('checkFolder' => false),
  166. 'models',
  167. 'Model',
  168. 'tests',
  169. 'Test' => array('regex' => '@class (\S*Test) extends CakeTestCase@'),
  170. 'views',
  171. 'View',
  172. 'vendors/shells',
  173. );
  174. $defaultOptions = array(
  175. 'recursive' => true,
  176. 'checkFolder' => true,
  177. 'regex' => '@class (\S*) .*{@i'
  178. );
  179. foreach($sourceDirs as $dir => $options) {
  180. if (is_numeric($dir)) {
  181. $dir = $options;
  182. $options = array();
  183. }
  184. $options = array_merge($defaultOptions, $options);
  185. $this->_movePhpFiles($dir, $options);
  186. }
  187. }
  188. /**
  189. * Update helpers.
  190. *
  191. * - Converts helpers usage to new format.
  192. *
  193. * @return void
  194. */
  195. public function helpers() {
  196. $this->_paths = array_diff(App::path('views'), App::core('views'));
  197. if (!empty($this->params['plugin'])) {
  198. $this->_paths = array(App::pluginPath($this->params['plugin']) . 'views' . DS);
  199. }
  200. $patterns = array();
  201. $helpers = App::objects('helper');
  202. $plugins = App::objects('plugin');
  203. $pluginHelpers = array();
  204. foreach ($plugins as $plugin) {
  205. $pluginHelpers = array_merge(
  206. $pluginHelpers,
  207. App::objects('helper', App::pluginPath($plugin) . DS . 'views' . DS . 'helpers' . DS, false)
  208. );
  209. }
  210. $helpers = array_merge($pluginHelpers, $helpers);
  211. foreach ($helpers as $helper) {
  212. $helper = preg_replace('/Helper$/', '', $helper);
  213. $oldHelper = strtolower(substr($helper, 0, 1)).substr($helper, 1);
  214. $patterns[] = array(
  215. "\${$oldHelper} to \$this->{$helper}",
  216. "/\\\${$oldHelper}->/",
  217. "\\\$this->{$helper}->"
  218. );
  219. }
  220. $this->_filesRegexpUpdate($patterns);
  221. }
  222. /**
  223. * Update i18n.
  224. *
  225. * - Removes extra true param.
  226. * - Add the echo to __*() calls that didn't need them before.
  227. *
  228. * @return void
  229. */
  230. public function i18n() {
  231. $this->_paths = array(
  232. APP
  233. );
  234. if (!empty($this->params['plugin'])) {
  235. $this->_paths = array(App::pluginPath($this->params['plugin']));
  236. }
  237. $patterns = array(
  238. array(
  239. '<?php __*(*) to <?php echo __*(*)',
  240. '/<\?php\s*(__[a-z]*\(.*?\))/',
  241. '<?php echo \1'
  242. ),
  243. array(
  244. '<?php __*(*, true) to <?php echo __*()',
  245. '/<\?php\s*(__[a-z]*\(.*?)(,\s*true)(\))/',
  246. '<?php echo \1\3'
  247. ),
  248. array('__*(*, true) to __*(*)', '/(__[a-z]*\(.*?)(,\s*true)(\))/', '\1\3')
  249. );
  250. $this->_filesRegexpUpdate($patterns);
  251. }
  252. /**
  253. * Upgrade the removed basics functions.
  254. *
  255. * - a(*) -> array(*)
  256. * - e(*) -> echo *
  257. * - ife(*, *, *) -> !empty(*) ? * : *
  258. * - a(*) -> array(*)
  259. * - r(*, *, *) -> str_replace(*, *, *)
  260. * - up(*) -> strtoupper(*)
  261. * - low(*, *, *) -> strtolower(*)
  262. * - getMicrotime() -> microtime(true)
  263. *
  264. * @return void
  265. */
  266. public function basics() {
  267. $this->_paths = array(
  268. APP
  269. );
  270. if (!empty($this->params['plugin'])) {
  271. $this->_paths = array(App::pluginPath($this->params['plugin']));
  272. }
  273. $patterns = array(
  274. array(
  275. 'a(*) -> array(*)',
  276. '/\ba\((.*)\)/',
  277. 'array(\1)'
  278. ),
  279. array(
  280. 'e(*) -> echo *',
  281. '/\be\((.*)\)/',
  282. 'echo \1'
  283. ),
  284. array(
  285. 'ife(*, *, *) -> !empty(*) ? * : *',
  286. '/ife\((.*), (.*), (.*)\)/',
  287. '!empty(\1) ? \2 : \3'
  288. ),
  289. array(
  290. 'r(*, *, *) -> str_replace(*, *, *)',
  291. '/\br\(/',
  292. 'str_replace('
  293. ),
  294. array(
  295. 'up(*) -> strtoupper(*)',
  296. '/\bup\(/',
  297. 'strtoupper('
  298. ),
  299. array(
  300. 'low(*) -> strtolower(*)',
  301. '/\blow\(/',
  302. 'strtolower('
  303. ),
  304. array(
  305. 'getMicrotime() -> microtime(true)',
  306. '/getMicrotime\(\)/',
  307. 'microtime(true)'
  308. ),
  309. );
  310. $this->_filesRegexpUpdate($patterns);
  311. }
  312. /**
  313. * Update the properties moved to CakeRequest.
  314. *
  315. * @return void
  316. */
  317. public function request() {
  318. $views = array_diff(App::path('views'), App::core('views'));
  319. $controllers = array_diff(App::path('controllers'), App::core('controllers'), array(APP));
  320. $components = array_diff(App::path('components'), App::core('components'));
  321. $this->_paths = array_merge($views, $controllers, $components);
  322. if (!empty($this->params['plugin'])) {
  323. $pluginPath = App::pluginPath($this->params['plugin']);
  324. $this->_paths = array(
  325. $pluginPath . 'controllers' . DS,
  326. $pluginPath . 'controllers' . DS . 'components' .DS,
  327. $pluginPath . 'views' . DS,
  328. );
  329. }
  330. $patterns = array(
  331. array(
  332. '$this->data -> $this->request->data',
  333. '/(\$this->data\b(?!\())/',
  334. '$this->request->data'
  335. ),
  336. array(
  337. '$this->params -> $this->request->params',
  338. '/(\$this->params\b(?!\())/',
  339. '$this->request->params'
  340. ),
  341. array(
  342. '$this->webroot -> $this->request->webroot',
  343. '/(\$this->webroot\b(?!\())/',
  344. '$this->request->webroot'
  345. ),
  346. array(
  347. '$this->base -> $this->request->base',
  348. '/(\$this->base\b(?!\())/',
  349. '$this->request->base'
  350. ),
  351. array(
  352. '$this->here -> $this->request->here',
  353. '/(\$this->here\b(?!\())/',
  354. '$this->request->here'
  355. ),
  356. array(
  357. '$this->action -> $this->request->action',
  358. '/(\$this->action\b(?!\())/',
  359. '$this->request->action'
  360. ),
  361. );
  362. $this->_filesRegexpUpdate($patterns);
  363. }
  364. /**
  365. * Update Configure::read() calls with no params.
  366. *
  367. * @return void
  368. */
  369. public function configure() {
  370. $this->_paths = array(
  371. APP
  372. );
  373. if (!empty($this->params['plugin'])) {
  374. $this->_paths = array(App::pluginPath($this->params['plugin']));
  375. }
  376. $patterns = array(
  377. array(
  378. "Configure::read() -> Configure::read('debug')",
  379. '/Configure::read\(\)/',
  380. 'Configure::read(\'debug\')'
  381. ),
  382. );
  383. $this->_filesRegexpUpdate($patterns);
  384. }
  385. /**
  386. * constants
  387. *
  388. * @return void
  389. */
  390. public function constants() {
  391. $this->_paths = array(
  392. APP
  393. );
  394. if (!empty($this->params['plugin'])) {
  395. $this->_paths = array(App::pluginPath($this->params['plugin']));
  396. }
  397. $patterns = array(
  398. array(
  399. "LIBS -> CAKE",
  400. '/\bLIBS\b/',
  401. 'CAKE'
  402. ),
  403. array(
  404. "CONFIGS -> APP . 'Config' . DS",
  405. '/\bCONFIGS\b/',
  406. 'APP . \'Config\' . DS'
  407. ),
  408. array(
  409. "CONTROLLERS -> APP . 'Controller' . DS",
  410. '/\bCONTROLLERS\b/',
  411. 'APP . \'Controller\' . DS'
  412. ),
  413. array(
  414. "COMPONENTS -> APP . 'Controller' . DS . 'Component' . DS",
  415. '/\bCOMPONENTS\b/',
  416. 'APP . \'Controller\' . DS . \'Component\''
  417. ),
  418. array(
  419. "MODELS -> APP . 'Model' . DS",
  420. '/\bMODELS\b/',
  421. 'APP . \'Model\' . DS'
  422. ),
  423. array(
  424. "BEHAVIORS -> APP . 'Model' . DS . 'Behavior' . DS",
  425. '/\bBEHAVIORS\b/',
  426. 'APP . \'Model\' . DS . \'Behavior\' . DS'
  427. ),
  428. array(
  429. "VIEWS -> APP . 'View' . DS",
  430. '/\bVIEWS\b/',
  431. 'APP . \'View\' . DS'
  432. ),
  433. array(
  434. "HELPERS -> APP . 'View' . DS . 'Helper' . DS",
  435. '/\bHELPERS\b/',
  436. 'APP . \'View\' . DS . \'Helper\' . DS'
  437. ),
  438. array(
  439. "LAYOUTS -> APP . 'View' . DS . 'Layouts' . DS",
  440. '/\bLAYOUTS\b/',
  441. 'APP . \'View\' . DS . \'Layouts\' . DS'
  442. ),
  443. array(
  444. "ELEMENTS -> APP . 'View' . DS . 'Elements' . DS",
  445. '/\bELEMENTS\b/',
  446. 'APP . \'View\' . DS . \'Elements\' . DS'
  447. ),
  448. array(
  449. "CONSOLE_LIBS -> CAKE . 'Console' . DS",
  450. '/\bCONSOLE_LIBS\b/',
  451. 'CAKE . \'Console\' . DS'
  452. ),
  453. array(
  454. "CAKE_TESTS_LIB -> CAKE . 'TestSuite' . DS",
  455. '/\bCAKE_TESTS_LIB\b/',
  456. 'CAKE . \'TestSuite\' . DS'
  457. ),
  458. array(
  459. "CAKE_TESTS -> CAKE . 'Test' . DS",
  460. '/\bCAKE_TESTS\b/',
  461. 'CAKE . \'Test\' . DS'
  462. )
  463. );
  464. $this->_filesRegexpUpdate($patterns);
  465. }
  466. /**
  467. * Update components.
  468. *
  469. * - Make components that extend Object to extend Component.
  470. *
  471. * @return void
  472. */
  473. public function components() {
  474. $this->_paths = App::Path('Controller/Component');
  475. if (!empty($this->params['plugin'])) {
  476. $this->_paths = App::Path('Controller/Component', $this->params['plugin']);
  477. }
  478. $patterns = array(
  479. array(
  480. '*Component extends Object to *Component extends Component',
  481. '/([a-zA-Z]*Component extends) Object/',
  482. '\1 Component'
  483. ),
  484. );
  485. $this->_filesRegexpUpdate($patterns);
  486. }
  487. /**
  488. * Move application views files to where they now should be
  489. *
  490. * Find all view files in the folder and determine where cake expects the file to be
  491. *
  492. * @return void
  493. */
  494. protected function _moveViewFiles() {
  495. if (!is_dir('View')) {
  496. return;
  497. }
  498. $dirs = scandir('View');
  499. foreach ($dirs as $old) {
  500. if (!is_dir('View' . DS . $old) || $old === '.' || $old === '..') {
  501. continue;
  502. }
  503. $new = 'View' . DS . Inflector::camelize($old);
  504. $old = 'View' . DS . $old;
  505. if ($new == $old) {
  506. continue;
  507. }
  508. $this->out(__d('cake_console', 'Moving %s to %s', $old, $new));
  509. if (!$this->params['dry-run']) {
  510. if ($this->params['git']) {
  511. exec('git mv -f ' . escapeshellarg($old) . ' ' . escapeshellarg($old . '__'));
  512. exec('git mv -f ' . escapeshellarg($old . '__') . ' ' . escapeshellarg($new));
  513. } else {
  514. $Folder = new Folder($old);
  515. $Folder->move($new);
  516. }
  517. }
  518. }
  519. }
  520. /**
  521. * Move application php files to where they now should be
  522. *
  523. * Find all php files in the folder (honoring recursive) and determine where cake expects the file to be
  524. * If the file is not exactly where cake expects it - move it.
  525. *
  526. * @param mixed $path
  527. * @param mixed $options array(recursive, checkFolder)
  528. * @return void
  529. */
  530. protected function _movePhpFiles($path, $options) {
  531. if (!is_dir($path)) {
  532. return;
  533. }
  534. $paths = $this->_paths;
  535. $this->_paths = array($path);
  536. $this->_files = array();
  537. if ($options['recursive']) {
  538. $this->_findFiles('php');
  539. } else {
  540. $this->_files = scandir($path);
  541. foreach($this->_files as $i => $file) {
  542. if (strlen($file) < 5 || substr($file, -4) !== '.php') {
  543. unset($this->_files[$i]);
  544. }
  545. }
  546. }
  547. $cwd = getcwd();
  548. foreach ($this->_files as &$file) {
  549. $file = $cwd . DS . $file;
  550. $contents = file_get_contents($file);
  551. preg_match($options['regex'], $contents, $match);
  552. if (!$match) {
  553. continue;
  554. }
  555. $class = $match[1];
  556. if (substr($class, 0, 3) === 'Dbo') {
  557. $type = 'Dbo';
  558. } else {
  559. preg_match('@([A-Z][^A-Z]*)$@', $class, $match);
  560. if ($match) {
  561. $type = $match[1];
  562. } else {
  563. $type = 'unknown';
  564. }
  565. }
  566. preg_match('@^.*[\\\/]plugins[\\\/](.*?)[\\\/]@', $file, $match);
  567. $base = $cwd . DS;
  568. $plugin = false;
  569. if ($match) {
  570. $base = $match[0];
  571. $plugin = $match[1];
  572. }
  573. if ($options['checkFolder'] && !empty($this->_map[$type])) {
  574. $folder = str_replace('/', DS, $this->_map[$type]);
  575. $new = $base . $folder . DS . $class . '.php';
  576. } else {
  577. $new = dirname($file) . DS . $class . '.php';
  578. }
  579. if ($file === $new) {
  580. continue;
  581. }
  582. $dir = dirname($new);
  583. if (!is_dir($dir)) {
  584. new Folder($dir, true);
  585. }
  586. $this->out(__d('cake_console', 'Moving %s to %s', $file, $new), 1, Shell::VERBOSE);
  587. if (!$this->params['dry-run']) {
  588. if ($this->params['git']) {
  589. exec('git mv -f ' . escapeshellarg($file) . ' ' . escapeshellarg($file . '__'));
  590. exec('git mv -f ' . escapeshellarg($file. '__') . ' ' . escapeshellarg($new));
  591. } else {
  592. rename($file, $new);
  593. }
  594. }
  595. }
  596. $this->_paths = $paths;
  597. }
  598. /**
  599. * Updates files based on regular expressions.
  600. *
  601. * @param array $patterns Array of search and replacement patterns.
  602. * @return void
  603. */
  604. protected function _filesRegexpUpdate($patterns) {
  605. $this->_findFiles($this->params['ext']);
  606. foreach ($this->_files as $file) {
  607. $this->out(__d('cake_console', 'Updating %s...', $file), 1, Shell::VERBOSE);
  608. $this->_updateFile($file, $patterns);
  609. }
  610. }
  611. /**
  612. * Searches the paths and finds files based on extension.
  613. *
  614. * @param string $extensions
  615. * @return void
  616. */
  617. protected function _findFiles($extensions = '') {
  618. foreach ($this->_paths as $path) {
  619. if (!is_dir($path)) {
  620. continue;
  621. }
  622. $this->_files = array();
  623. $Iterator = new RegexIterator(
  624. new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)),
  625. '/^.+\.(' . $extensions . ')$/i',
  626. RegexIterator::MATCH
  627. );
  628. foreach ($Iterator as $file) {
  629. if ($file->isFile()) {
  630. $this->_files[] = $file->getPathname();
  631. }
  632. }
  633. }
  634. }
  635. /**
  636. * Update a single file.
  637. *
  638. * @param string $file The file to update
  639. * @param array $patterns The replacement patterns to run.
  640. * @return void
  641. */
  642. protected function _updateFile($file, $patterns) {
  643. $contents = file_get_contents($file);
  644. foreach ($patterns as $pattern) {
  645. $this->out(__d('cake_console', ' * Updating %s', $pattern[0]), 1, Shell::VERBOSE);
  646. $contents = preg_replace($pattern[1], $pattern[2], $contents);
  647. }
  648. $this->out(__d('cake_console', 'Done updating %s', $file), 1);
  649. if (!$this->params['dry-run']) {
  650. file_put_contents($file, $contents);
  651. }
  652. }
  653. /**
  654. * get the option parser
  655. *
  656. * @return ConsoleOptionParser
  657. */
  658. public function getOptionParser() {
  659. $subcommandParser = array(
  660. 'options' => array(
  661. 'plugin' => array(
  662. 'short' => 'p',
  663. 'help' => __d('cake_console', 'The plugin to update. Only the specified plugin will be updated.')
  664. ),
  665. 'ext' => array(
  666. 'short' => 'e',
  667. 'help' => __d('cake_console', 'The extension(s) to search. A pipe delimited list, or a preg_match compatible subpattern'),
  668. 'default' => 'php|ctp|thtml|inc|tpl'
  669. ),
  670. 'git' => array(
  671. 'short' => 'g',
  672. 'help' => __d('cake_console', 'Use git command for moving files around.'),
  673. 'boolean' => true
  674. ),
  675. 'dry-run'=> array(
  676. 'short' => 'd',
  677. 'help' => __d('cake_console', 'Dry run the update, no files will actually be modified.'),
  678. 'boolean' => true
  679. )
  680. )
  681. );
  682. return parent::getOptionParser()
  683. ->description(__d('cake_console', "A shell to help automate upgrading from CakePHP 1.3 to 2.0. \n" .
  684. "Be sure to have a backup of your application before running these commands."))
  685. ->addSubcommand('all', array(
  686. 'help' => __d('cake_console', 'Run all upgrade commands.'),
  687. 'parser' => $subcommandParser
  688. ))
  689. ->addSubcommand('tests', array(
  690. 'help' => __d('cake_console', 'Update tests class names to FooTest rather than FooTestCase.'),
  691. 'parser' => $subcommandParser
  692. ))
  693. ->addSubcommand('locations', array(
  694. 'help' => __d('cake_console', 'Move files and folders to their new homes.'),
  695. 'parser' => $subcommandParser
  696. ))
  697. ->addSubcommand('i18n', array(
  698. 'help' => __d('cake_console', 'Update the i18n translation method calls.'),
  699. 'parser' => $subcommandParser
  700. ))
  701. ->addSubcommand('helpers', array(
  702. 'help' => __d('cake_console', 'Update calls to helpers.'),
  703. 'parser' => $subcommandParser
  704. ))
  705. ->addSubcommand('basics', array(
  706. 'help' => __d('cake_console', 'Update removed basics functions to PHP native functions.'),
  707. 'parser' => $subcommandParser
  708. ))
  709. ->addSubcommand('request', array(
  710. 'help' => __d('cake_console', 'Update removed request access, and replace with $this->request.'),
  711. 'parser' => $subcommandParser
  712. ))
  713. ->addSubcommand('configure', array(
  714. 'help' => __d('cake_console', "Update Configure::read() to Configure::read('debug')"),
  715. 'parser' => $subcommandParser
  716. ))
  717. ->addSubcommand('constants', array(
  718. 'help' => __d('cake_console', "Replace Obsolete constants"),
  719. 'parser' => $subcommandParser
  720. ))
  721. ->addSubcommand('components', array(
  722. 'help' => __d('cake_console', 'Update components to extend Component class.'),
  723. 'parser' => $subcommandParser
  724. ));
  725. }
  726. }