mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2026-01-04 03:54:51 +01:00
Added methods to delete speedtests
This commit is contained in:
@@ -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.'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user