public function __construct() { parent::__construct(); $this->contentProviders = ModelContentProvider::all(); if ($this->input('organisation')) { $this->organisations = ModelOrganisation::getByQuery($this->input('organisation'), 20, 0); } }
// -- CLEANUP THUMBNAILS --- echo chr(10) . ' [ CLEANING UNUSED THUMBNAILS ]' . chr(10) . chr(10); $thumbnails = \NinjaImg\Model\ModelThumbnail::getByMaxAge(THUMBNAIL_MAX_AGE_DAYS); if (!$thumbnails->hasRows()) { echo ' - No thumbnails found'; } else { /* @var $thumbnail \NinjaImg\Model\ModelThumbnail */ foreach ($thumbnails->getRows() as $thumbnail) { echo ' - Deleting thumbnail: ' . $thumbnail->name . chr(10); $thumbnail->delete(); } } echo chr(10) . chr(10); // DETECT DISKSPACE CHANGES echo ' [ CHECK CONTENT-PROVIDER DISKSPACE ]' . chr(10) . chr(10); foreach (\NinjaImg\Model\ModelContentProvider::all(true) as $cdn) { echo ' + Checking ' . $cdn->name . chr(10); $total = $cdn->capacity_max_gb && $cdn->capacity_max_gb > 0 ? $cdn->capacity_max_gb : round(disk_total_space($cdn->path) / 1024 / 1024 / 1024); $capacity = round(disk_free_space($cdn->path) / 1024 / 1024 / 1024); $leftPercentage = round($capacity / $total * 100); $lastRun = isset($settings['last_run']) ? $settings['last_run'] : 'Not available'; /** * Send warning if the storage left is <= NOTIFY_MIN_SPACE_PERCENTAGE * OTHERWISE * send notification if change is > NOTIFY_PERCENTAGE_CHANGE */ $cdn->active = true; if ($leftPercentage <= NOTIFY_MIN_SPACE_PERCENTAGE) { echo ' - [WARNING] Storage critical: ' . $cdn->capacity_free_gb . '/' . $total . 'GB left' . chr(10); mailAdmins('WARNING: STORAGE ALMOST EMPTY ' . $cdn->name, "Yo, bitches!\n\nWARNING: content-provider \"{$cdn->name}\" has almost exceeded it's disk space and has disabled automatically.\n\nLast recorded date: {$lastRun}\nLast recorded diskspace: " . round($cdn->capacity_free_gb) . "GB\nDiskspace available: " . round($capacity) . "GB\nDiskspace limit: " . round($total) . "GB\n\n- The Ninja Robot"); $cdn->active = false;