UpgradeShell.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  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 = 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. $oldHelper = strtolower(substr($helper, 0, 1)).substr($helper, 1);
  213. $patterns[] = array(
  214. "\${$oldHelper} to \$this->{$helper}",
  215. "/\\\${$oldHelper}->/",
  216. "\\\$this->{$helper}->"
  217. );
  218. }
  219. $this->_filesRegexpUpdate($patterns);
  220. }
  221. /**
  222. * Update i18n.
  223. *
  224. * - Removes extra true param.
  225. * - Add the echo to __*() calls that didn't need them before.
  226. *
  227. * @return void
  228. */
  229. public function i18n() {
  230. $this->_paths = array(
  231. APP
  232. );
  233. if (!empty($this->params['plugin'])) {
  234. $this->_paths = array(App::pluginPath($this->params['plugin']));
  235. }
  236. $patterns = array(
  237. array(
  238. '<?php __*(*) to <?php echo __*(*)',
  239. '/<\?php\s*(__[a-z]*\(.*?\))/',
  240. '<?php echo \1'
  241. ),
  242. array(
  243. '<?php __*(*, true) to <?php echo __*()',
  244. '/<\?php\s*(__[a-z]*\(.*?)(,\s*true)(\))/',
  245. '<?php echo \1\3'
  246. ),
  247. array('__*(*, true) to __*(*)', '/(__[a-z]*\(.*?)(,\s*true)(\))/', '\1\3')
  248. );
  249. $this->_filesRegexpUpdate($patterns);
  250. }
  251. /**
  252. * Upgrade the removed basics functions.
  253. *
  254. * - a(*) -> array(*)
  255. * - e(*) -> echo *
  256. * - ife(*, *, *) -> !empty(*) ? * : *
  257. * - a(*) -> array(*)
  258. * - r(*, *, *) -> str_replace(*, *, *)
  259. * - up(*) -> strtoupper(*)
  260. * - low(*, *, *) -> strtolower(*)
  261. * - getMicrotime() -> microtime(true)
  262. *
  263. * @return void
  264. */
  265. public function basics() {
  266. $this->_paths = array(
  267. APP
  268. );
  269. if (!empty($this->params['plugin'])) {
  270. $this->_paths = array(App::pluginPath($this->params['plugin']));
  271. }
  272. $patterns = array(
  273. array(
  274. 'a(*) -> array(*)',
  275. '/\ba\((.*)\)/',
  276. 'array(\1)'
  277. ),
  278. array(
  279. 'e(*) -> echo *',
  280. '/\be\((.*)\)/',
  281. 'echo \1'
  282. ),
  283. array(
  284. 'ife(*, *, *) -> !empty(*) ? * : *',
  285. '/ife\((.*), (.*), (.*)\)/',
  286. '!empty(\1) ? \2 : \3'
  287. ),
  288. array(
  289. 'r(*, *, *) -> str_replace(*, *, *)',
  290. '/\br\(/',
  291. 'str_replace('
  292. ),
  293. array(
  294. 'up(*) -> strtoupper(*)',
  295. '/\bup\(/',
  296. 'strtoupper('
  297. ),
  298. array(
  299. 'low(*) -> strtolower(*)',
  300. '/\blow\(/',
  301. 'strtolower('
  302. ),
  303. array(
  304. 'getMicrotime() -> microtime(true)',
  305. '/getMicrotime\(\)/',
  306. 'microtime(true)'
  307. ),
  308. );
  309. $this->_filesRegexpUpdate($patterns);
  310. }
  311. /**
  312. * Update the properties moved to CakeRequest.
  313. *
  314. * @return void
  315. */
  316. public function request() {
  317. $views = array_diff(App::path('views'), App::core('views'));
  318. $controllers = array_diff(App::path('controllers'), App::core('controllers'), array(APP));
  319. $components = array_diff(App::path('components'), App::core('components'));
  320. $this->_paths = array_merge($views, $controllers, $components);
  321. if (!empty($this->params['plugin'])) {
  322. $pluginPath = App::pluginPath($this->params['plugin']);
  323. $this->_paths = array(
  324. $pluginPath . 'controllers' . DS,
  325. $pluginPath . 'controllers' . DS . 'components' .DS,
  326. $pluginPath . 'views' . DS,
  327. );
  328. }
  329. $patterns = array(
  330. array(
  331. '$this->data -> $this->request->data',
  332. '/(\$this->data\b(?!\())/',
  333. '$this->request->data'
  334. ),
  335. array(
  336. '$this->params -> $this->request->params',
  337. '/(\$this->params\b(?!\())/',
  338. '$this->request->params'
  339. ),
  340. array(
  341. '$this->webroot -> $this->request->webroot',
  342. '/(\$this->webroot\b(?!\())/',
  343. '$this->request->webroot'
  344. ),
  345. array(
  346. '$this->base -> $this->request->base',
  347. '/(\$this->base\b(?!\())/',
  348. '$this->request->base'
  349. ),
  350. array(
  351. '$this->here -> $this->request->here',
  352. '/(\$this->here\b(?!\())/',
  353. '$this->request->here'
  354. ),
  355. array(
  356. '$this->action -> $this->request->action',
  357. '/(\$this->action\b(?!\())/',
  358. '$this->request->action'
  359. ),
  360. );
  361. $this->_filesRegexpUpdate($patterns);
  362. }
  363. /**
  364. * Update Configure::read() calls with no params.
  365. *
  366. * @return void
  367. */
  368. public function configure() {
  369. $this->_paths = array(
  370. APP
  371. );
  372. if (!empty($this->params['plugin'])) {
  373. $this->_paths = array(App::pluginPath($this->params['plugin']));
  374. }
  375. $patterns = array(
  376. array(
  377. "Configure::read() -> Configure::read('debug')",
  378. '/Configure::read\(\)/',
  379. 'Configure::read(\'debug\')'
  380. ),
  381. );
  382. $this->_filesRegexpUpdate($patterns);
  383. }
  384. /**
  385. * constants
  386. *
  387. * @return void
  388. */
  389. public function constants() {
  390. $this->_paths = array(
  391. APP
  392. );
  393. if (!empty($this->params['plugin'])) {
  394. $this->_paths = array(App::pluginPath($this->params['plugin']));
  395. }
  396. $patterns = array(
  397. array(
  398. "LIBS -> CAKE",
  399. '/\bLIBS\b/',
  400. 'CAKE'
  401. ),
  402. array(
  403. "CONFIGS -> APP . 'Config' . DS",
  404. '/\bCONFIGS\b/',
  405. 'APP . \'Config\' . DS'
  406. ),
  407. array(
  408. "CONTROLLERS -> APP . 'Controller' . DS",
  409. '/\bCONTROLLERS\b/',
  410. 'APP . \'Controller\' . DS'
  411. ),
  412. array(
  413. "COMPONENTS -> APP . 'Controller' . DS . 'Component' . DS",
  414. '/\bCOMPONENTS\b/',
  415. 'APP . \'Controller\' . DS . \'Component\''
  416. ),
  417. array(
  418. "MODELS -> APP . 'Model' . DS",
  419. '/\bMODELS\b/',
  420. 'APP . \'Model\' . DS'
  421. ),
  422. array(
  423. "BEHAVIORS -> APP . 'Model' . DS . 'Behavior' . DS",
  424. '/\bBEHAVIORS\b/',
  425. 'APP . \'Model\' . DS . \'Behavior\' . DS'
  426. ),
  427. array(
  428. "VIEWS -> APP . 'View' . DS",
  429. '/\bVIEWS\b/',
  430. 'APP . \'View\' . DS'
  431. ),
  432. array(
  433. "HELPERS -> APP . 'View' . DS . 'Helper' . DS",
  434. '/\bHELPERS\b/',
  435. 'APP . \'View\' . DS . \'Helper\' . DS'
  436. ),
  437. array(
  438. "LAYOUTS -> APP . 'View' . DS . 'Layouts' . DS",
  439. '/\bLAYOUTS\b/',
  440. 'APP . \'View\' . DS . \'Layouts\' . DS'
  441. ),
  442. array(
  443. "ELEMENTS -> APP . 'View' . DS . 'Elements' . DS",
  444. '/\bELEMENTS\b/',
  445. 'APP . \'View\' . DS . \'Elements\' . DS'
  446. ),
  447. array(
  448. "CONSOLE_LIBS -> CAKE . 'Console' . DS",
  449. '/\bCONSOLE_LIBS\b/',
  450. 'CAKE . \'Console\' . DS'
  451. ),
  452. array(
  453. "CAKE_TESTS_LIB -> CAKE . 'TestSuite' . DS",
  454. '/\bCAKE_TESTS_LIB\b/',
  455. 'CAKE . \'TestSuite\' . DS'
  456. ),
  457. array(
  458. "CAKE_TESTS -> CAKE . 'Test' . DS",
  459. '/\bCAKE_TESTS\b/',
  460. 'CAKE . \'Test\' . DS'
  461. )
  462. );
  463. $this->_filesRegexpUpdate($patterns);
  464. }
  465. /**
  466. * Update components.
  467. *
  468. * - Make components that extend Object to extend Component.
  469. *
  470. * @return void
  471. */
  472. public function components() {
  473. $this->_paths = App::Path('Controller/Component');
  474. if (!empty($this->params['plugin'])) {
  475. $this->_paths = App::Path('Controller/Component', $this->params['plugin']);
  476. }
  477. $patterns = array(
  478. array(
  479. '*Component extends Object to *Component extends Component',
  480. '/([a-zA-Z]*Component extends) Object/',
  481. '\1 Component'
  482. ),
  483. );
  484. $this->_filesRegexpUpdate($patterns);
  485. }
  486. /**
  487. * Move application views files to where they now should be
  488. *
  489. * Find all view files in the folder and determine where cake expects the file to be
  490. *
  491. * @return void
  492. */
  493. protected function _moveViewFiles() {
  494. if (!is_dir('View')) {
  495. return;
  496. }
  497. $dirs = scandir('View');
  498. foreach ($dirs as $old) {
  499. if (!is_dir('View' . DS . $old) || $old === '.' || $old === '..') {
  500. continue;
  501. }
  502. $new = 'View' . DS . Inflector::camelize($old);
  503. $old = 'View' . DS . $old;
  504. if ($new == $old) {
  505. continue;
  506. }
  507. $this->out(__d('cake_console', 'Moving %s to %s', $old, $new));
  508. if (!$this->params['dry-run']) {
  509. if ($this->params['git']) {
  510. exec('git mv -f ' . escapeshellarg($old) . ' ' . escapeshellarg($old . '__'));
  511. exec('git mv -f ' . escapeshellarg($old . '__') . ' ' . escapeshellarg($new));
  512. } else {
  513. $Folder = new Folder($old);
  514. $Folder->move($new);
  515. }
  516. }
  517. }
  518. }
  519. /**
  520. * Move application php files to where they now should be
  521. *
  522. * Find all php files in the folder (honoring recursive) and determine where cake expects the file to be
  523. * If the file is not exactly where cake expects it - move it.
  524. *
  525. * @param mixed $path
  526. * @param mixed $options array(recursive, checkFolder)
  527. * @return void
  528. */
  529. protected function _movePhpFiles($path, $options) {
  530. if (!is_dir($path)) {
  531. return;
  532. }
  533. $paths = $this->_paths;
  534. $this->_paths = array($path);
  535. $this->_files = array();
  536. if ($options['recursive']) {
  537. $this->_findFiles('php');
  538. } else {
  539. $this->_files = scandir($path);
  540. foreach($this->_files as $i => $file) {
  541. if (strlen($file) < 5 || substr($file, -4) !== '.php') {
  542. unset($this->_files[$i]);
  543. }
  544. }
  545. }
  546. $cwd = getcwd();
  547. foreach ($this->_files as &$file) {
  548. $file = $cwd . DS . $file;
  549. $contents = file_get_contents($file);
  550. preg_match($options['regex'], $contents, $match);
  551. if (!$match) {
  552. continue;
  553. }
  554. $class = $match[1];
  555. if (substr($class, 0, 3) === 'Dbo') {
  556. $type = 'Dbo';
  557. } else {
  558. preg_match('@([A-Z][^A-Z]*)$@', $class, $match);
  559. if ($match) {
  560. $type = $match[1];
  561. } else {
  562. $type = 'unknown';
  563. }
  564. }
  565. preg_match('@^.*[\\\/]plugins[\\\/](.*?)[\\\/]@', $file, $match);
  566. $base = $cwd . DS;
  567. $plugin = false;
  568. if ($match) {
  569. $base = $match[0];
  570. $plugin = $match[1];
  571. }
  572. if ($options['checkFolder'] && !empty($this->_map[$type])) {
  573. $folder = str_replace('/', DS, $this->_map[$type]);
  574. $new = $base . $folder . DS . $class . '.php';
  575. } else {
  576. $new = dirname($file) . DS . $class . '.php';
  577. }
  578. if ($file === $new) {
  579. continue;
  580. }
  581. $dir = dirname($new);
  582. if (!is_dir($dir)) {
  583. new Folder($dir, true);
  584. }
  585. $this->out(__d('cake_console', 'Moving %s to %s', $file, $new), 1, Shell::VERBOSE);
  586. if (!$this->params['dry-run']) {
  587. if ($this->params['git']) {
  588. exec('git mv -f ' . escapeshellarg($file) . ' ' . escapeshellarg($file . '__'));
  589. exec('git mv -f ' . escapeshellarg($file. '__') . ' ' . escapeshellarg($new));
  590. } else {
  591. rename($file, $new);
  592. }
  593. }
  594. }
  595. $this->_paths = $paths;
  596. }
  597. /**
  598. * Updates files based on regular expressions.
  599. *
  600. * @param array $patterns Array of search and replacement patterns.
  601. * @return void
  602. */
  603. protected function _filesRegexpUpdate($patterns) {
  604. $this->_findFiles($this->params['ext']);
  605. foreach ($this->_files as $file) {
  606. $this->out(__d('cake_console', 'Updating %s...', $file), 1, Shell::VERBOSE);
  607. $this->_updateFile($file, $patterns);
  608. }
  609. }
  610. /**
  611. * Searches the paths and finds files based on extension.
  612. *
  613. * @param string $extensions
  614. * @return void
  615. */
  616. protected function _findFiles($extensions = '') {
  617. foreach ($this->_paths as $path) {
  618. if (!is_dir($path)) {
  619. continue;
  620. }
  621. $this->_files = array();
  622. $Iterator = new RegexIterator(
  623. new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)),
  624. '/^.+\.(' . $extensions . ')$/i',
  625. RegexIterator::MATCH
  626. );
  627. foreach ($Iterator as $file) {
  628. if ($file->isFile()) {
  629. $this->_files[] = $file->getPathname();
  630. }
  631. }
  632. }
  633. }
  634. /**
  635. * Update a single file.
  636. *
  637. * @param string $file The file to update
  638. * @param array $patterns The replacement patterns to run.
  639. * @return void
  640. */
  641. protected function _updateFile($file, $patterns) {
  642. $contents = file_get_contents($file);
  643. foreach ($patterns as $pattern) {
  644. $this->out(__d('cake_console', ' * Updating %s', $pattern[0]), 1, Shell::VERBOSE);
  645. $contents = preg_replace($pattern[1], $pattern[2], $contents);
  646. }
  647. $this->out(__d('cake_console', 'Done updating %s', $file), 1);
  648. if (!$this->params['dry-run']) {
  649. file_put_contents($file, $contents);
  650. }
  651. }
  652. /**
  653. * get the option parser
  654. *
  655. * @return ConsoleOptionParser
  656. */
  657. public function getOptionParser() {
  658. $subcommandParser = array(
  659. 'options' => array(
  660. 'plugin' => array(
  661. 'short' => 'p',
  662. 'help' => __d('cake_console', 'The plugin to update. Only the specified plugin will be updated.')
  663. ),
  664. 'ext' => array(
  665. 'short' => 'e',
  666. 'help' => __d('cake_console', 'The extension(s) to search. A pipe delimited list, or a preg_match compatible subpattern'),
  667. 'default' => 'php|ctp|thtml|inc|tpl'
  668. ),
  669. 'git' => array(
  670. 'short' => 'g',
  671. 'help' => __d('cake_console', 'Use git command for moving files around.'),
  672. 'boolean' => true
  673. ),
  674. 'dry-run'=> array(
  675. 'short' => 'd',
  676. 'help' => __d('cake_console', 'Dry run the update, no files will actually be modified.'),
  677. 'boolean' => true
  678. )
  679. )
  680. );
  681. return parent::getOptionParser()
  682. ->description(__d('cake_console', "A shell to help automate upgrading from CakePHP 1.3 to 2.0. \n" .
  683. "Be sure to have a backup of your application before running these commands."))
  684. ->addSubcommand('all', array(
  685. 'help' => __d('cake_console', 'Run all upgrade commands.'),
  686. 'parser' => $subcommandParser
  687. ))
  688. ->addSubcommand('tests', array(
  689. 'help' => __d('cake_console', 'Update tests class names to FooTest rather than FooTestCase.'),
  690. 'parser' => $subcommandParser
  691. ))
  692. ->addSubcommand('locations', array(
  693. 'help' => __d('cake_console', 'Move files and folders to their new homes.'),
  694. 'parser' => $subcommandParser
  695. ))
  696. ->addSubcommand('i18n', array(
  697. 'help' => __d('cake_console', 'Update the i18n translation method calls.'),
  698. 'parser' => $subcommandParser
  699. ))
  700. ->addSubcommand('helpers', array(
  701. 'help' => __d('cake_console', 'Update calls to helpers.'),
  702. 'parser' => $subcommandParser
  703. ))
  704. ->addSubcommand('basics', array(
  705. 'help' => __d('cake_console', 'Update removed basics functions to PHP native functions.'),
  706. 'parser' => $subcommandParser
  707. ))
  708. ->addSubcommand('request', array(
  709. 'help' => __d('cake_console', 'Update removed request access, and replace with $this->request.'),
  710. 'parser' => $subcommandParser
  711. ))
  712. ->addSubcommand('configure', array(
  713. 'help' => __d('cake_console', "Update Configure::read() to Configure::read('debug')"),
  714. 'parser' => $subcommandParser
  715. ))
  716. ->addSubcommand('constants', array(
  717. 'help' => __d('cake_console', "Replace Obsolete constants"),
  718. 'parser' => $subcommandParser
  719. ))
  720. ->addSubcommand('components', array(
  721. 'help' => __d('cake_console', 'Update components to extend Component class.'),
  722. 'parser' => $subcommandParser
  723. ));
  724. }
  725. }