App\Commands\AppController::actionClearAssets PHP Method

actionClearAssets() public method

Clear [application]/web/assets folder.
public actionClearAssets ( )
    public function actionClearAssets()
    {
        $assets = \Yii::getAlias('@web/assets');
        // Matches from 7-8 char folder names, the 8. char is optional
        $matchRegex = '"^[a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9]\\?[a-z0-9]$"';
        // create $cmd command
        $cmd = 'cd "' . $assets . '" && ls | grep -e ' . $matchRegex . ' | xargs rm -rf ';
        // Set command
        $command = new Command($cmd);
        // Prompt user
        $delete = $this->confirm("\nDo you really want to delete web assets?", true);
        if ($delete) {
            // Try to execute $command
            if ($command->execute()) {
                echo "Web assets have been deleted.\n\n";
            } else {
                echo "\n" . $command->getError() . "\n";
                echo $command->getStdErr();
            }
        }
    }