Server : Apache/2.4.41 (Ubuntu) System : Linux journalup 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/html/classes/plugins/ |
<?php /** * @file classes/plugins/PubObjectCache.inc.php * * Copyright (c) 2014-2020 Simon Fraser University * Copyright (c) 2003-2020 John Willinsky * Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. * * @class PubObjectCache * @ingroup plugins * * @brief A cache for publication objects required during export. */ class PubObjectCache { /* @var array */ var $_objectCache = array(); // // Public API // /** * Add a publishing object to the cache. * @param $object Issue|Submission|ArticleGalley * @param $parent Submission|null Only required when adding a galley. */ function add($object, $parent) { if (is_a($object, 'Issue')) { $this->_insertInternally($object, 'issues', $object->getId()); } if (is_a($object, 'Submission')) { $this->_insertInternally($object, 'articles', $object->getId()); $this->_insertInternally($object, 'articlesByIssue', $object->getcurrentPublication()->getData('issueId'), $object->getId()); } if (is_a($object, 'ArticleGalley')) { assert(is_a($parent, 'Submission')); $this->_insertInternally($object, 'galleys', $object->getId()); $this->_insertInternally($object, 'galleysByArticle', $object->getSubmissionId(), $object->getId()); $this->_insertInternally($object, 'galleysByIssue', $parent->getIssueId(), $object->getId()); } } /** * Marks the given cache id "complete", i.e. it * contains all child objects for the given object * id. * * @param $cacheId * @param $objectId */ function markComplete($cacheId, $objectId) { assert(is_array($this->_objectCache[$cacheId][$objectId])); $this->_objectCache[$cacheId][$objectId]['complete'] = true; // Order objects in the completed cache by ID. ksort($this->_objectCache[$cacheId][$objectId]); } /** * Retrieve (an) object(s) from the cache. * * NB: You must check whether an object is in the cache * before you try to retrieve it with this method. * * @param $cacheId string * @param $id1 integer * @param $id2 integer * * @return mixed */ function get($cacheId, $id1, $id2 = null) { assert($this->isCached($cacheId, $id1, $id2)); if (is_null($id2)) { $returner = $this->_objectCache[$cacheId][$id1]; if (is_array($returner)) unset($returner['complete']); return $returner; } else { return $this->_objectCache[$cacheId][$id1][$id2]; } } /** * Check whether a given object is in the cache. * * @param $cacheId string * @param $id1 integer * @param $id2 integer * * @return boolean */ function isCached($cacheId, $id1, $id2 = null) { if (!isset($this->_objectCache[$cacheId])) return false; $id1 = (int)$id1; if (is_null($id2)) { if (!isset($this->_objectCache[$cacheId][$id1])) return false; if (is_array($this->_objectCache[$cacheId][$id1])) { return isset($this->_objectCache[$cacheId][$id1]['complete']); } else { return true; } } else { $id2 = (int)$id2; return isset($this->_objectCache[$cacheId][$id1][$id2]); } } // // Private helper methods // /** * Insert an object into the cache. * * @param $object object * @param $cacheId string * @param $id1 integer * @param $id2 integer */ function _insertInternally($object, $cacheId, $id1, $id2 = null) { if ($this->isCached($cacheId, $id1, $id2)) return; if (!isset($this->_objectCache[$cacheId])) { $this->_objectCache[$cacheId] = array(); } $id1 = (int)$id1; if (is_null($id2)) { $this->_objectCache[$cacheId][$id1] = $object; } else { $id2 = (int)$id2; if (!isset($this->_objectCache[$cacheId][$id1])) { $this->_objectCache[$cacheId][$id1] = array(); } $this->_objectCache[$cacheId][$id1][$id2] = $object; } } }