/
home
/
assocoweys
/
leucate
/
plugins
/
system
/
autocleanedocman
/
Upload File
HOME
<?php defined('_JEXEC') or die; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\Filesystem\Folder; use Joomla\Filesystem\File; use Joomla\Filesystem\Path; use Joomla\CMS\Log\Log; class PlgSystemAutocleanedocman extends CMSPlugin { protected $autoloadLanguage = true; public function onAfterInitialise() { try { // Get plugin parameters $interval = (int) $this->params->get('interval', 30) * 60; // Convert minutes to seconds $lastRunFile = JPATH_CACHE . '/autocleanedocman_lastrun.txt'; // Check last run time $lastRun = 0; if (is_file(Path::clean($lastRunFile))) { $content = @file_get_contents($lastRunFile); if ($content !== false) { $lastRun = (int) $content; } } $currentTime = time(); if ($currentTime - $lastRun >= $interval) { // Perform cleanup $this->cleanDirectory(); // Update last run time if (@file_put_contents($lastRunFile, $currentTime) === false) { Log::add('Failed to update last run time for AutoCleanEdocman plugin.', Log::WARNING, 'plg_system_autocleanedocman'); } } } catch (Exception $e) { Log::add('Error in AutoCleanEdocman plugin: ' . $e->getMessage(), Log::ERROR, 'plg_system_autocleanedocman'); } } private function cleanDirectory() { $path = JPATH_ROOT . '/edocmanviewer'; if (!is_dir(Path::clean($path))) { Log::add('Directory ' . $path . ' does not exist.', Log::INFO, 'plg_system_autocleanedocman'); return; } // Delete files (except .htaccess) $files = Folder::files($path, '.', false, false, ['.htaccess']); foreach ($files as $file) { if (!File::delete($path . '/' . $file)) { Log::add('Failed to delete file: ' . $file, Log::WARNING, 'plg_system_autocleanedocman'); } } // Delete folders $folders = Folder::folders($path, '.', false, false); foreach ($folders as $folder) { if (!Folder::delete($path . '/' . $folder)) { Log::add('Failed to delete folder: ' . $folder, Log::WARNING, 'plg_system_autocleanedocman'); } } Log::add('Cleaned up files and folders in ' . $path, Log::INFO, 'plg_system_autocleanedocman'); } }