2015-07-16 21:32:42 +12:00
|
|
|
<?php
|
2016-06-23 11:37:22 +12:00
|
|
|
|
2016-08-19 10:51:35 +12:00
|
|
|
namespace SilverStripe\Dev\Tasks;
|
|
|
|
|
|
|
|
use SilverStripe\Control\Director;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Dev\BuildTask;
|
2016-06-23 11:37:22 +12:00
|
|
|
use SilverStripe\Security\Permission;
|
|
|
|
use SilverStripe\Security\Security;
|
2016-08-19 10:51:35 +12:00
|
|
|
|
2015-07-16 21:32:42 +12:00
|
|
|
/**
|
|
|
|
* Cleans up leftover databases from aborted test executions (starting with ss_tmpdb)
|
|
|
|
* Task is restricted to users with administrator rights or running through CLI.
|
|
|
|
*/
|
2016-03-10 10:15:19 +13:00
|
|
|
class CleanupTestDatabasesTask extends BuildTask {
|
2016-08-19 10:51:35 +12:00
|
|
|
|
|
|
|
private static $segment = 'CleanupTestDatabasesTask';
|
|
|
|
|
2015-07-16 21:32:42 +12:00
|
|
|
protected $title = 'Deletes all temporary test databases';
|
|
|
|
|
|
|
|
protected $description = 'Cleans up leftover databases from aborted test executions (starting with ss_tmpdb)';
|
|
|
|
|
2016-03-10 10:15:19 +13:00
|
|
|
public function run($request) {
|
2015-07-16 21:32:42 +12:00
|
|
|
if(!Permission::check('ADMIN') && !Director::is_cli()) {
|
2016-05-23 17:11:52 +01:00
|
|
|
$response = Security::permissionFailure();
|
2016-03-10 10:15:19 +13:00
|
|
|
if($response) {
|
|
|
|
$response->output();
|
|
|
|
}
|
|
|
|
die;
|
2015-07-16 21:32:42 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
SapphireTest::delete_all_temp_dbs();
|
|
|
|
}
|
|
|
|
|
2016-03-09 09:50:18 +13:00
|
|
|
}
|