Skip to content

Instantly share code, notes, and snippets.

@mbischof
Last active December 13, 2015 16:59
Show Gist options
  • Save mbischof/4944182 to your computer and use it in GitHub Desktop.
Save mbischof/4944182 to your computer and use it in GitHub Desktop.
an install command
<?php
class InstallCommand extends CConsoleCommand
{
public function actionIndex()
{
$this->createDir('images.cache');
$this->createDir('images.cache.thumbnails');
$tables = Yii::app()->db->schema->getTableNames();
foreach ($tables as $table) {
Yii::app()->db->createCommand()->dropTable($table);
}
$this
->commandRunner
->createCommand('migrate')
->run(array('up', '--interactive=0'));
}
protected function createDir($alias)
{
$webroot = realpath(Yii::app()->basePath . DIRECTORY_SEPARATOR . '..');
$path = $webroot
. DIRECTORY_SEPARATOR
. str_replace('.', DIRECTORY_SEPARATOR, $alias);
if (!file_exists($path)) {
mkdir($path);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment