Compare commits

..

2 Commits

Author SHA1 Message Date
GamerClassN7
64b50ead9f Notifications 2021-01-04 17:08:56 +01:00
GamerClassN7
a3a87d39d2 Fixes 2021-01-04 16:51:34 +01:00
4 changed files with 21 additions and 1 deletions

View File

@ -53,6 +53,7 @@ $router->any('/api/HA', 'GoogleHomeApi@response');
$router->post('/api/endpoint/', 'EndpointsApi@default');
$router->any('/api/update/', 'UpdatesApi@default');
$router->any('/api/users/status', 'UsersApi@status');
$router->any('/api/users/subscribe', 'UsersApi@subscribe');
// examples
$router->any('/api/example', 'ExampleApi@example');

View File

@ -12,6 +12,11 @@ class CronApi extends ApiController
$backupWorker = new DatabaseBackup();
$backupWorker->purge(5);
//Old Records Cleanup
foreach (SubDeviceManager::getAllSubDevices() as $key => $value) {
RecordManager::setHistory($value['subdevice_id']);
}
$this->response(['Value' => 'OK']);
}

View File

@ -34,4 +34,13 @@ class UsersApi extends ApiController{
}
$this->response(['value'=>'OK']);
}
public function subscribe(){
//$this->requireAuth();
$subscriptionToken = $this->input['token'];
$subscriptionUserId = $this->input['user_id'];
NotificationManager::addSubscriber($subscriptionUserId, $subscriptionToken);
$this->response(['value'=>'OK']);
}
}

View File

@ -102,7 +102,7 @@ class RecordManager{
public static function clean ($day) {
if (isset($day)) {
Db::command ('DELETE FROM records WHERE `time` < ADDDATE(NOW(), INTERVAL -? DAY);', array($day));
Db::command ('DELETE FROM records WHERE `time` < ADDDATE(NOW(), INTERVAL ? DAY);', array($day));
}
}
@ -110,5 +110,10 @@ class RecordManager{
public static function cleanSubdeviceRecords ($subDeviceId) {
Db::command ('DELETE FROM records WHERE subdevice_id = ?);', array($subDeviceId));
}
public static function setHistory($subDeviceId){
$history = SubDeviceManager::getSubDevice($subDeviceId)['history'];
if ($history > 0) self::clean(-abs($history));
}
}
?>