Permalink
Browse files

Remove garbage shell.

Add Pasteshell for expiring pastes.
  • Loading branch information...
1 parent 926f57f commit 9fb678522af9ed6b595478adfdf64b4ede1f1540 @markstory markstory committed Sep 2, 2012
Showing with 34 additions and 48 deletions.
  1. +0 −46 Console/Command/MainShell.php
  2. +32 −0 Console/Command/PasteShell.php
  3. +2 −2 Model/Paste.php
@@ -1,46 +0,0 @@
-<?php
-
-/**
- * 2011-11-07 ms
- */
-class MainShell extends Shell {
-
- /**
- * OK:
- * cake TestShell main
- * cake TestShell
- * cake TestShell main -f
- * ERROR:
- * cake TestShell -f
- *
- * the default command "main" does not get the correct subcommand parser attached if invoked inexplicitly
- */
- public function main() {
- $this->out('EXECUTE MAIN');
-
- $this->out(print_r($this->params, true));
-
- $this->out('EXECUTE MAIN END');
- }
-
- public function getOptionParser() {
- $subcommandParser = array(
- 'options' => array(
- 'foo'=> array(
- 'short' => 'f',
- 'help' => __d('cake_console', 'a param test'),
- 'boolean' => true
- )
- )
- );
-
- return parent::getOptionParser()
- ->description(__d('cake_console', "a test"))
- ->addSubcommand('main', array(
- 'help' => __d('cake_console', 'test of correct main execution'),
- 'parser' => $subcommandParser
- ));
- }
-
-}
-
@@ -0,0 +1,32 @@
+<?php
+
+class PasteShell extends AppShell {
+
+/**
+ * Models to load
+ *
+ * @var array
+ */
+ public $models = array('Paste');
+
+/**
+ * Expire old temporary pastes.
+ *
+ * @return void
+ */
+ public function expire() {
+ $age = '-1 day';
+ if (isset($this->args[0])) {
+ $age = $this->args[0];
+ }
+ $this->Paste->purgeTemporary($age);
+ }
+
+ public function getOptionParser() {
+ $parser = parent::getOptionParser();
+ $parser->addSubcommand('expire', array(
+ 'help' => 'Remove old temporary pastes from the database.'
+ ));
+ return $parser;
+ }
+}
View
@@ -193,10 +193,10 @@ protected function _findRecentVersions($state, $query, $results = array()) {
*
* @return boolean
*/
- public function purgeTemporary() {
+ public function purgeTemporary($age = '-1 day') {
$conditions = array(
'Paste.save' => 0,
- 'Paste.created <=' => date('Y-m-d', strtotime('-1 day'))
+ 'Paste.created <=' => date('Y-m-d', strtotime($age))
);
return $this->deleteAll($conditions);
}

0 comments on commit 9fb6785

Please sign in to comment.