Added methods to delete speedtests

This commit is contained in:
Henry Whitaker
2020-07-22 01:40:19 +01:00
parent 78260c014a
commit a952c09e70
13 changed files with 246 additions and 14 deletions

View File

@@ -5,6 +5,7 @@ namespace App\Helpers;
use App\Speedtest;
use Carbon\Carbon;
use Exception;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
@@ -253,4 +254,55 @@ class SpeedtestHelper {
return $rate;
}
/**
* Create a backup of the SQLite database
*
* @return boolean
*/
public static function dbBackup()
{
if(env('DB_CONNECTION') === 'sqlite') {
if(env('DB_DATABASE') !== null) {
$current = env('DB_DATABASE');
if(File::copy($current, $current . '.bak')) {
return true;
}
}
return false;
}
return null;
}
/**
* Delete all speedtests from the database
*
* @return boolean|string
*/
public static function deleteAll()
{
Cache::flush();
if(SpeedtestHelper::dbBackup() !== false) {
if(sizeof(Speedtest::whereNotNull('id')->get()) > 0) {
if(Speedtest::whereNotNull('id')->delete()) {
return [
'success' => true,
];
}
}
return [
'success' => true,
];
}
return [
'success' => false,
'msg' => 'There was an error backing up the database. No speedtests have been deleted.'
];
}
}