Created
April 5, 2013 10:14
-
-
Save samdark/5318196 to your computer and use it in GitHub Desktop.
Yii command to clear assets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Clear assets Command | |
* | |
* Deletes all published assets. | |
* | |
* Usage: | |
* yiic clearassets | |
* | |
* @author Alexander Makarov | |
*/ | |
class ClearAssetsCommand extends CConsoleCommand { | |
/** | |
* Executes the command. | |
* @param array command line parameters for this command. | |
*/ | |
public function run($args) | |
{ | |
$path = Yii::app()->getAssetManager()->getBasePath(); | |
$di = new DirectoryIterator($path); | |
foreach($di as $d) | |
{ | |
if(!$d->isDot()) | |
{ | |
echo "Removed ".$d->getPathname()."\n"; | |
$this->removeDirRecursive($d->getPathname()); | |
} | |
} | |
echo "Done.\n"; | |
} | |
function removeDirRecursive($dir) | |
{ | |
$files = glob($dir.'*', GLOB_MARK); | |
foreach ($files as $file) | |
{ | |
if (is_dir($file)){ | |
$this->removeDirRecursive($file); | |
} | |
else { | |
unlink($file); | |
} | |
} | |
if (is_dir($dir)) rmdir($dir); | |
} | |
} |
$path = '../assets/'; //Yii::app()->getAssetManager()->getBasePath();
that`s work!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
exception 'CException' with message 'CConsoleApplication and its behaviors do not have a method
or closure named "getAssetManager"