Browse Source

Improving the regex and moving more files around.

- Making the regex case insensitive so it can also matches capital C in class (ie. Class).
- Adding a new protected method to move view files, the directory will be camelized.
Renan Gonçalves 14 years ago
parent
commit
0bcb8d0dfa
1 changed files with 36 additions and 2 deletions
  1. 36 2
      lib/Cake/Console/Command/UpgradeShell.php

+ 36 - 2
lib/Cake/Console/Command/UpgradeShell.php

@@ -132,7 +132,6 @@ class UpgradeShell extends Shell {
 		}
 
 		if (is_dir('plugins')) {
-
 			$Folder = new Folder('plugins');
 			list($plugins) = $Folder->read();
 			foreach($plugins as $plugin) {
@@ -143,6 +142,8 @@ class UpgradeShell extends Shell {
 			chdir($cwd);
 		}
 
+		$this->_moveViewFiles();
+
 		$moves = array(
 			'libs' => 'Lib',
 			'tests' => 'Test',
@@ -181,7 +182,7 @@ class UpgradeShell extends Shell {
 		$defaultOptions = array(
 			'recursive' => true,
 			'checkFolder' => true,
-			'regex' => '@class (\S*) .*{@'
+			'regex' => '@class (\S*) .*{@i'
 		);
 		foreach($sourceDirs as $dir => $options) {
 			if (is_numeric($dir)) {
@@ -507,6 +508,39 @@ class UpgradeShell extends Shell {
 	}
 
 /**
+ * Move application views files to where they now should be
+ *
+ * Find all view files in the folder and determine where cake expects the file to be
+ *
+ * @return void
+ */
+	protected function _moveViewFiles() {
+		if (!is_dir('views')) {
+			return;
+		}
+
+		$dirs = scandir('views');
+		foreach ($dirs as $old) {
+			if (!is_dir('views' . DS . $old) || $old === '.' || $old === '..') {
+				continue;
+			}
+
+			$new = 'View' . DS . Inflector::camelize($old);
+			$old = 'views' . DS . $old;
+
+			$this->out(__d('cake_console', 'Moving %s to %s', $old, $new));
+			if (!$this->params['dry-run']) {
+				if ($this->params['git']) {
+					exec('git mv -f ' . escapeshellarg($old) . ' ' . escapeshellarg($new));
+				} else {
+					$Folder = new Folder($old);
+					$Folder->move($new);
+				}
+			}
+		}
+	}
+
+/**
  * Move application php files to where they now should be
  *
  * Find all php files in the folder (honoring recursive) and determine where cake expects the file to be