Browse Source

File creation checks at "AssetController" have been updated to use Exceptions.

tags/2.0.0-beta
Klimov Paul 12 years ago
parent
commit
6c179ef3a7
  1. 25
      framework/yii/console/controllers/AssetController.php

25
framework/yii/console/controllers/AssetController.php

@ -159,7 +159,7 @@ class AssetController extends Controller
} }
} }
$this->getAssetManager(); // check asset manager configuration $this->getAssetManager(); // check asset manager configuration is correct
} }
/** /**
@ -420,7 +420,7 @@ class AssetController extends Controller
} }
$array = var_export($array, true); $array = var_export($array, true);
$version = date('Y-m-d H:i:s', time()); $version = date('Y-m-d H:i:s', time());
$bytesWritten = file_put_contents($bundleFile, <<<EOD $bundleFileContent = <<<EOD
<?php <?php
/** /**
* This file is generated by the "yii script" command. * This file is generated by the "yii script" command.
@ -428,9 +428,8 @@ class AssetController extends Controller
* @version $version * @version $version
*/ */
return $array; return $array;
EOD EOD;
); if (!file_put_contents($bundleFile, $bundleFileContent)) {
if ($bytesWritten <= 0) {
throw new Exception("Unable to write output bundle configuration at '{$bundleFile}'."); throw new Exception("Unable to write output bundle configuration at '{$bundleFile}'.");
} }
echo "Output bundle configuration created at '{$bundleFile}'.\n"; echo "Output bundle configuration created at '{$bundleFile}'.\n";
@ -498,6 +497,7 @@ EOD
* Combines Java Script files into a single one. * Combines Java Script files into a single one.
* @param array $inputFiles source file names. * @param array $inputFiles source file names.
* @param string $outputFile output file name. * @param string $outputFile output file name.
* @throws \yii\console\Exception on failure.
*/ */
public function combineJsFiles($inputFiles, $outputFile) public function combineJsFiles($inputFiles, $outputFile)
{ {
@ -507,13 +507,16 @@ EOD
. file_get_contents($file) . file_get_contents($file)
. "/*** END FILE: $file ***/\n"; . "/*** END FILE: $file ***/\n";
} }
file_put_contents($outputFile, $content); if (!file_put_contents($outputFile, $content)) {
throw new Exception("Unable to write output Java Script file '{$outputFile}'.");
}
} }
/** /**
* Combines CSS files into a single one. * Combines CSS files into a single one.
* @param array $inputFiles source file names. * @param array $inputFiles source file names.
* @param string $outputFile output file name. * @param string $outputFile output file name.
* @throws \yii\console\Exception on failure.
*/ */
public function combineCssFiles($inputFiles, $outputFile) public function combineCssFiles($inputFiles, $outputFile)
{ {
@ -523,7 +526,9 @@ EOD
. $this->adjustCssUrl(file_get_contents($file), dirname($file), dirname($outputFile)) . $this->adjustCssUrl(file_get_contents($file), dirname($file), dirname($outputFile))
. "/*** END FILE: $file ***/\n"; . "/*** END FILE: $file ***/\n";
} }
file_put_contents($outputFile, $content); if (!file_put_contents($outputFile, $content)) {
throw new Exception("Unable to write output CSS file '{$outputFile}'.");
}
} }
/** /**
@ -590,6 +595,7 @@ EOD
/** /**
* Creates template of configuration file for [[actionCompress]]. * Creates template of configuration file for [[actionCompress]].
* @param string $configFile output file name. * @param string $configFile output file name.
* @throws \yii\console\Exception on failure.
*/ */
public function actionTemplate($configFile) public function actionTemplate($configFile)
{ {
@ -622,9 +628,8 @@ EOD;
return; return;
} }
} }
$bytesWritten = file_put_contents($configFile, $template); if (!file_put_contents($configFile, $template)) {
if ($bytesWritten<=0) { throw new Exception("Unable to write template file '{$configFile}'.");
echo "Error: unable to write file '{$configFile}'!\n\n";
} else { } else {
echo "Configuration file template created at '{$configFile}'.\n\n"; echo "Configuration file template created at '{$configFile}'.\n\n";
} }

Loading…
Cancel
Save