Fixes
This commit is contained in:
		@@ -12,6 +12,11 @@ class CronApi extends ApiController
 | 
				
			|||||||
		$backupWorker = new DatabaseBackup();
 | 
							$backupWorker = new DatabaseBackup();
 | 
				
			||||||
		$backupWorker->purge(5);
 | 
							$backupWorker->purge(5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Old Records Cleanup
 | 
				
			||||||
 | 
							foreach (SubDeviceManager::getAllSubDevices() as $key => $value) {
 | 
				
			||||||
 | 
								RecordManager::setHistory($value['subdevice_id']);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$this->response(['Value' => 'OK']);
 | 
							$this->response(['Value' => 'OK']);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -102,7 +102,7 @@ class RecordManager{
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	public static function clean ($day) {
 | 
						public static function clean ($day) {
 | 
				
			||||||
		if (isset($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) {
 | 
						public static function cleanSubdeviceRecords ($subDeviceId) {
 | 
				
			||||||
		Db::command ('DELETE FROM records WHERE subdevice_id = ?);', array($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));
 | 
				
			||||||
 | 
						} 
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
?>
 | 
					?>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user