Skip to content

Commit

Permalink
Clear cache command
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbrendel committed Nov 23, 2024
1 parent 5c6face commit 1edf406
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
32 changes: 32 additions & 0 deletions app/commands/CacheClearCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
Asatru PHP - Command handler
*/

/**
* Command handler class
*/
class CacheClearCommand implements Asatru\Commands\Command {
/**
* Command handler method
*
* @param $args
* @return void
*/
public function handle($args)
{
echo "Clearing cache...\n";

try {
CacheModel::clear();
} catch (\Exception $e) {
echo "\033[31mOperation failed: {$e->getMessage()}\033[39m\n";

return;
}

echo "\033[32mDone!\033[39m\n";
}
}

3 changes: 2 additions & 1 deletion app/config/commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
['product:version', 'Show current product version', 'VersionCommand'],
['migrate:upgrade', 'Perform version specific migration upgrades', 'MigrationUpgrade'],
['calendar:classes', 'Add default calendar classes', 'CalendarClsCommand'],
['plants:attributes', 'Add default plant attributes', 'AttributesCommand']
['plants:attributes', 'Add default plant attributes', 'AttributesCommand'],
['cache:clear', 'Clear the entire cache', 'CacheClearCommand']
];
10 changes: 10 additions & 0 deletions app/models/CacheModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ public static function forget($ident)

return false;
}

/**
* Clear entire cache
*
* @return void
*/
public static function clear()
{
static::raw('DELETE FROM `' . self::tableName() . '`');
}

/**
* Return the associated table name of the migration
Expand Down

0 comments on commit 1edf406

Please sign in to comment.