PHP_SMART_HOME_V3/app/api/CronApi.php

64 lines
1.5 KiB
PHP
Raw Normal View History

2020-10-14 12:35:04 +00:00
<?php
2020-10-22 14:42:49 +00:00
class CronApi extends ApiController
{
2020-08-25 13:12:25 +00:00
2020-10-22 14:42:49 +00:00
public function clean()
{
//Log Cleaning
$logKeeper = new LogMaintainer();
$logKeeper->purge(LOGTIMOUT);
2020-10-22 15:59:45 +00:00
2020-10-25 23:01:30 +00:00
//Database Backup Cleanup
2020-10-22 14:42:49 +00:00
$backupWorker = new DatabaseBackup();
$backupWorker->purge(5);
2020-08-25 13:12:25 +00:00
2021-01-04 15:51:34 +00:00
//Old Records Cleanup
foreach (SubDeviceManager::getAllSubDevices() as $key => $value) {
RecordManager::setHistory($value['subdevice_id']);
}
2020-10-22 14:42:49 +00:00
$this->response(['Value' => 'OK']);
}
2020-10-14 12:35:04 +00:00
2020-10-22 14:42:49 +00:00
public function fetch()
{
//Run Plugins
$result = [];
$dir = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . 'app/plugins/';
2020-10-22 15:59:45 +00:00
$pluginsFiles = array_diff(scandir($dir), ['..', '.']);
2020-10-22 14:42:49 +00:00
foreach ($pluginsFiles as $key => $pluginFile) {
2020-10-25 23:01:30 +00:00
if (strpos($pluginFile, "!") === false) {
$className = str_replace(".php", "", $pluginFile);
if (strpos($pluginFile, '_') === true) {
continue;
}
if (!class_exists($className)) {
continue;
}
$pluginMakeClass = new $className;
if (!method_exists($pluginMakeClass, 'make')) {
2020-10-22 15:59:45 +00:00
2020-10-25 23:01:30 +00:00
continue;
}
$result[$className] = $pluginMakeClass->make();
} else {
$className = str_replace("!", "", str_replace(".php", "", $pluginFile));
if (strpos($pluginFile, '_') === true) {
continue;
}
if (!class_exists($className)) {
continue;
}
$pluginMakeClass = new $className;
if (!method_exists($pluginMakeClass, 'disable')) {
continue;
}
$result[$className] = $pluginMakeClass->disable();
2020-10-22 15:59:45 +00:00
}
2020-10-22 14:42:49 +00:00
}
2020-10-22 15:59:45 +00:00
2020-10-22 14:42:49 +00:00
//Print Result
$this->response($result);
}
2020-10-14 12:35:04 +00:00
}