Browse Source

Simplify FolderLib::clear

euromark 12 years ago
parent
commit
6fe605e08d

+ 3 - 1
Console/Command/PhpTagShell.php

@@ -3,7 +3,7 @@ App::uses('AppShell', 'Console/Command');
 App::uses('Folder', 'Utility');
 
 /**
- * removes closing php tag (?>) from php files
+ * Removes closing php tag (?>) from php files
  * it also makes sure there is no whitespace at the beginning of the file
  *
  * @author Mark Scherer, Maximilian Ruta
@@ -21,6 +21,8 @@ class PhpTagShell extends AppShell {
 	);
 
 	public function main() {
+		$this->out('Removes closing php tag (?>) from php files.', 2);
+
 		$this->out('Usage: cake Tools.PhpTag run [/path/or/file]');
 	}
 

+ 5 - 3
Console/Command/WhitespaceShell.php

@@ -29,7 +29,7 @@ class WhitespaceShell extends AppShell {
 		$this->out('Found '. count($files) . ' files.');
 
 		$action = $this->in(__('Continue? [y]/[n]'), array('y', 'n'), 'n');
-		if ($action === 'n') {
+		if ($action !== 'y') {
 			return $this->error('Aborted');
 		}
 
@@ -38,6 +38,7 @@ class WhitespaceShell extends AppShell {
 		foreach ($files as $file) {
 			$error = '';
 			$action = '';
+			$this->out('Processing ' . $file, 1, Shell::VERBOSE);
 
 			$c = file_get_contents($file);
 			if (preg_match('/^[\n\r|\n\r|\n|\r|\s]+\<\?php/', $c)) {
@@ -92,7 +93,7 @@ class WhitespaceShell extends AppShell {
 
 				file_put_contents($file, $res);
 				$this->report[$error][1]++;
-				$this->out('fixed '.$error.' whitespaces: '.$this->shortPath($file));
+				$this->out('fixed ' . $error . ' whitespaces: ' . $this->shortPath($file));
 			}
 		}
 
@@ -121,11 +122,12 @@ class WhitespaceShell extends AppShell {
 		$this->out('Found '. count($files) . ' files.');
 
 		$action = $this->in(__('Continue? [y]/[n]'), array('y', 'n'), 'n');
-		if ($action === 'n') {
+		if ($action !== 'y') {
 			return $this->error('Aborted');
 		}
 
 		foreach ($files as $file) {
+			$this->out('Processing ' . $file, 1, Shell::VERBOSE);
 			$content = $store = file_get_contents($file);
 
 			$newline = PHP_EOL;

+ 21 - 23
Lib/Utility/FolderLib.php

@@ -13,6 +13,8 @@ class FolderLib extends Folder {
 	 * Instead of deleting the folder itself as delete() does,
 	 * this method only removes its content recursivly.
 	 *
+	 * Note: It skips hidden folders (starting with a . dot).
+	 *
 	 * @return boolean Success or null on invalid folder
 	 * 2010-12-07 ms
 	 */
@@ -24,33 +26,29 @@ class FolderLib extends Folder {
 			return null;
 		}
 		$path = Folder::slashTerm($path);
-		if (is_dir($path)) {
-			$normalFiles = glob($path . '*');
-			$hiddenFiles = glob($path . '\.?*');
+		if (!is_dir($path)) {
+			return null;
+		}
+		$normalFiles = glob($path . '*');
+		$hiddenFiles = glob($path . '\.?*');
 
-			$normalFiles = $normalFiles ? $normalFiles : array();
-			$hiddenFiles = $hiddenFiles ? $hiddenFiles : array();
+		$normalFiles = $normalFiles ? $normalFiles : array();
+		$hiddenFiles = $hiddenFiles ? $hiddenFiles : array();
 
-			$files = array_merge($normalFiles, $hiddenFiles);
-			if (is_array($files)) {
-				foreach ($files as $file) {
-					if (preg_match('/(\.|\.\.)$/', $file)) {
-						continue;
-					}
-					chmod($file, 0770);
-					if (is_file($file)) {
-						if (@unlink($file)) {
-							$this->_messages[] = __('%s removed', $file);
-						} else {
-							$this->_errors[] = __('%s NOT removed', $file);
-						}
-					} elseif (is_dir($file) && $this->delete($file) === false) {
-						return false;
-					}
+		$files = array_merge($normalFiles, $hiddenFiles);
+		foreach ($files as $file) {
+			if (preg_match('/(\.|\.\.)$/', $file)) {
+				continue;
+			}
+			if (is_file($file)) {
+				if (@unlink($file)) {
+					$this->_messages[] = __('%s removed', $file);
+				} else {
+					$this->_errors[] = __('%s NOT removed', $file);
 				}
+			} elseif (is_dir($file) && $this->delete($file) === false) {
+				return false;
 			}
-		} else {
-			unlink($path);
 		}
 		return true;
 	}

+ 23 - 1
Test/Case/Lib/Utility/FolderLibTest.php

@@ -18,5 +18,27 @@ class FolderLibTest extends MyCakeTestCase {
 		$this->assertInstanceOf('FolderLib', $this->FolderLib);
 	}
 
-	//TODO
+	/**
+	 * FolderLibTest::testClear()
+	 *
+	 * @return void
+	 */
+	public function testClear() {
+		$folder = TMP;
+		mkdir($folder . 'x' . DS . 'y', 0770, true);
+		touch($folder . 'x' . DS . 'y' . DS . 'one.txt');
+		touch($folder . 'x' . DS . 'two.txt');
+
+		$Folder = new FolderLib($folder . 'x');
+		$result = $Folder->clear();
+		$this->assertTrue($result);
+
+		$this->assertTrue(is_dir($folder . 'x'));
+		$this->assertFalse(is_dir($folder . 'x' . DS . 'y'));
+		$this->assertFalse(is_file($folder . 'x' . DS . 'two.txt'));
+
+		$Folder->delete($folder . 'x');
+		$this->assertFalse(is_file($folder . 'x'));
+	}
+
 }

+ 5 - 5
View/Helper/FormExtHelper.php

@@ -644,21 +644,21 @@ class FormExtHelper extends FormHelper {
 
 		$customOptions = array(
 			'id' => $modelName.$fieldName.'-dd',
-			'class' => 'day'
+			'class' => 'form-control day'
 		);
 		$customOptions = array_merge($defaultOptions, $customOptions, $options);
 		$res['d'] = $this->day($field, $customOptions);
 
 		$customOptions = array(
 			'id' => $modelName.$fieldName.'-mm',
-			'class' => 'month'
+			'class' => 'form-control month'
 		);
 		$customOptions = array_merge($defaultOptions, $customOptions, $options);
 		$res['m'] = $this->month($field, $customOptions);
 
 		$customOptions = array(
 			'id' => $modelName.$fieldName,
-			'class' => 'year'
+			'class' => 'form-control year'
 		);
 		$customOptions = array_merge($defaultOptions, $customOptions, $options);
 		$minYear = $customOptions['minYear'];
@@ -802,10 +802,10 @@ class FormExtHelper extends FormHelper {
 			$model = $this->model();
 		}
 
-		$hourOptions = array_merge($customOptions, array('class'=>'hour'));
+		$hourOptions = array_merge($customOptions, array('class'=>'form-control hour'));
 		$res['h'] = $this->hour($field, $format24Hours, $hourOptions);
 
-		$minuteOptions = array_merge($customOptions, array('class'=>'minute'));
+		$minuteOptions = array_merge($customOptions, array('class'=>'form-control minute'));
 		$res['m'] = $this->minute($field, $minuteOptions);
 
 		$select = implode($options['separator'], $res);