/
home
/
assocoweys
/
leucate
/
plugins
/
system
/
edocmancheckfile
/
Upload File
HOME
<?php /** * @version 1.22.0 * @package Joomla * @subpackage Edocman * @author Tuan Pham Ngoc * @copyright Copyright (C) 2012 - 2024 Ossolution Team * @license GNU/GPL, see LICENSE.php */ defined('_JEXEC') or die; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\Factory; use Joomla\CMS\Cache\Cache; class plgSystemEDocmanCheckfile extends CMSPlugin { public function onAfterRender() { if (file_exists(JPATH_ROOT . '/components/com_edocman/edocman.php')) { jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); $lastRun = (int) $this->params->get('last_run', 0); $now = time(); $cacheTime = 1; // 60 minutes if (($now - $lastRun) < $cacheTime) { return; } //Store last run time $db = Factory::getDbo(); $query = $db->getQuery(true); $insertQuery = $db->getQuery(true); $this->params->set('last_run', $now); $params = $this->params->toString(); $query->clear(); $query->update('#__extensions') ->set('params=' . $db->quote($params)) ->where('`element`="edocmancheckfile"') ->where('`folder`="system"'); try { // Lock the tables to prevent multiple plugin executions causing a race condition $db->lockTable('#__extensions'); } catch (Exception $e) { // If we can't lock the tables it's too risk continuing execution return; } try { // Update the plugin parameters $result = $db->setQuery($query)->execute(); $this->clearCacheGroups(array('com_plugins'), array(0, 1)); } catch (Exception $exc) { // If we failed to execite $db->unlockTables(); $result = false; } try { // Unlock the tables after writing $db->unlockTables(); } catch (Exception $e) { // If we can't lock the tables assume we have somehow failed $result = false; } // Abort on failure if (!$result) { return; } require_once JPATH_ROOT . '/components/com_edocman/helper/helper.php'; require_once JPATH_ADMINISTRATOR . '/components/com_edocman/table/document.php'; $config = EDocmanHelper::getConfig(); $path = $config->documents_path; $path = str_replace("\\", "/", $path); $path = rtrim($path, '/'); $fields = array_keys($db->getTableColumns('#__edocman_documents')); if (!in_array('missing_files', $fields)) { $sql = "ALTER TABLE `#__edocman_licenses` ADD `missing_files` tinyint(1) NOT NULL DEFAULT '0';"; $db->setQuery($sql); $db->execute(); } if (!in_array('checked_on', $fields)) { $sql = "ALTER TABLE `#__edocman_licenses` ADD `checked_on` int(11) NOT NULL DEFAULT '0';"; $db->setQuery($sql); $db->execute(); } if(!EdocmanHelper::isDropBoxTurnedOn() && !EDocmanHelper::isAmazonS3TurnedOn() && !EDocmanHelper::isGdriveTurnedOn()) { $currentTime = time(); $lastFifteenMins = $currentTime - 15*60; $query->clear()->select('id, filename')->from('#__edocman_documents')->where('checked_on < "'.$lastFifteenMins.'"'); $db->setQuery($query); $documents = $db->loadObjectList(); if(count($documents)) { foreach ($documents as $document) { if(!file_exists($path .'/'. $document->filename)) { $db->setQuery("Update #__edocman_documents set missing_files = '1', checked_on = '".time()."' where id = '$document->id'"); $db->execute(); } else { $db->setQuery("Update #__edocman_documents set checked_on = '".time()."' where id = '$document->id'"); $db->execute(); } } } } } return true; } /** * Clears cache groups. We use it to clear the plugins cache after we update the last run timestamp. * * @param array $clearGroups The cache groups to clean * @param array $cacheClients The cache clients (site, admin) to clean * * @return void * * @since 1.6.8 */ private function clearCacheGroups(array $clearGroups, array $cacheClients = array(0, 1)) { $conf = Factory::getConfig(); foreach ($clearGroups as $group) { foreach ($cacheClients as $client_id) { try { $options = array( 'defaultgroup' => $group, 'cachebase' => ($client_id) ? JPATH_ADMINISTRATOR . '/cache' : $conf->get('cache_path', JPATH_SITE . '/cache') ); $cache = Cache::getInstance('callback', $options); $cache->clean(); } catch (Exception $e) { // Ignore it } } } } }