Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Jul 22, 2014
0 parents commit 47adcea
Show file tree
Hide file tree
Showing 188 changed files with 16,058 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Config/Schema/schema.php
Original file line number Diff line number Diff line change
@@ -0,0 1,20 @@
<?php
class SetupSchema extends CakeSchema {

public function before($event = array()) {
return true;
}

public function after($event = array()) {
}

public $settings = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'primary'),
'key' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 50, 'collate' => 'utf8_unicode_ci', 'charset' => 'utf8'),
'value' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_unicode_ci', 'charset' => 'utf8'),
'modified' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)),
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_unicode_ci', 'engine' => 'MyISAM')
);

}
122 changes: 122 additions & 0 deletions Console/Command/CleanupShell.php
Original file line number Diff line number Diff line change
@@ -0,0 1,122 @@
<?php
App::uses('AppShell', 'Console/Command');
App::uses('ConnectionManager', 'Model');

/**
* Cleanup Shell
*
* @author Mark Scherer
* @license MIT
*/
class CleanupShell extends AppShell {

/**
* Shell startup, prints info message about dry run.
*
* @return void
*/
public function startup() {
parent::startup();
if ($this->params['dry-run']) {
$this->out(__d('cake_console', '<warning>Dry-run mode enabled!</warning>'), 1, Shell::QUIET);
}
}

/**
* Display help.
*
* @return void
*/
public function main() {
$this->help();
}

//@deprecated with new command parser help?
public function help() {
$help = <<<TEXT
The Cleanup Shell takes care of some cleanup stuff to be done once in a while
---------------------------------------------------------------
Usage: cake Setup.Cleanup <command>
---------------------------------------------------------------
Commands:
help
shows this help message.
tables
delete tmp and test tables
Params:
-v (verbose)
-d (dry-run)
TEXT;
$this->out($help);
}

/**
* Remove all test/tmp tables
*
* @return void
*/
public function tables() {
$db = ConnectionManager::getDataSource('default');
//$res = $db->query('show tables');
$sources = $db->listSources();

$toDelete = array();
foreach ($sources as $source) {
if (preg_match('/^test_/', $source)) {
$toDelete[] = $source;
$this->out('- ' . $source);
}
}

$in = $this->in('Continue?', array('y', 'n'), 'n');
if ($in !== 'y') {
return $this->error('Aborted!');
}

foreach ($toDelete as $tableName) {
$db->query('DROP TABLE IF EXISTS `' . $tableName . '`');
}

$this->out(count($toDelete) . ' removed');

/*
if (!empty($this->args)) {
$this->_removeTables($this->args);
} else {
$this->_removeTables();
}
*/
$this->out('Done');
}

/**
* Get the option parser
*
* @return ConsoleOptionParser
*/
public function getOptionParser() {
$subcommandParser = array(
'options' => array(
'dry-run' => array(
'short' => 'd',
'help' => __d('cake_console', 'Dry run the clear command, no tables will actually be dropped. Should be combined with verbose!'),
'boolean' => true
)
)
);

return parent::getOptionParser()
->description(__d('cake_console', "The Clear Shell deletes all tmp files (cache, logs)"))
->addSubcommand('tables', array(
'help' => __d('cake_console', 'Clear tmp/test tables'),
'parser' => $subcommandParser
));
}

}
Loading

0 comments on commit 47adcea

Please sign in to comment.