Browse Source

Improve error handling and output messages display.

ADmad 11 years ago
parent
commit
ee684832b5
1 changed files with 26 additions and 17 deletions
  1. 26 17
      src/Shell/Task/AssetsTask.php

+ 26 - 17
src/Shell/Task/AssetsTask.php

@@ -60,42 +60,51 @@ class AssetsTask extends Shell {
 
 			$link = Inflector::underscore($plugin);
 			$dir = WWW_ROOT;
-			if (file_exists($dir . $link)) {
-				$this->out($link . ' already exists');
-				$this->out();
-				continue;
-			}
 
 			if (strpos('/', $link) !== false) {
 				$parts = explode('/', $link);
 				$link = array_pop($parts);
 				$dir = WWW_ROOT . implode(DS, $parts) . DS;
 				if (!is_dir($dir)) {
-					$this->out('Creating directory: ' . $dir);
-					$this->out();
 					$old = umask(0);
-					mkdir($dir, 0755, true);
+					// @codingStandardsIgnoreStart
+					$result = @mkdir($dir, 0755, true);
+					// @codingStandardsIgnoreEnd
 					umask($old);
+
+					if ($result) {
+						$this->out('Created directory ' . $dir);
+					} else {
+						$this->err('Failed creating directory ' . $dir);
+						continue;
+					}
 				}
 			}
 
-			$this->out('Creating symlink: ' . $dir);
-			$this->out();
+			if (file_exists($dir . $link)) {
+				$this->out($link . ' already exists', 1, Shell::VERBOSE);
+				continue;
+			}
+
 			// @codingStandardsIgnoreStart
 			$result = @symlink($path, $dir . $link);
 			// @codingStandardsIgnoreEnd
 
-			if (!$result) {
-				$this->err('Symlink creation failed');
-				$this->out('Copying to directory:' . $dir);
-				$this->out();
-				$folder = new Folder($path);
-				$folder->copy(['to' => $dir . $link]);
+			if ($result) {
+				$this->out('Created symlink ' . $dir . $link);
+				continue;
+			}
+
+			$folder = new Folder($path);
+			if ($folder->copy(['to' => $dir . $link])) {
+				$this->out('Copied assets to directory ' . $dir);
+			} else {
+				$this->err('Error copying assets to directory ' . $dir);
 			}
 		}
 
 		$this->out();
-		$this->out('Done.');
+		$this->out('Done');
 	}
 
 }