/** * @see wcf\page\MultipleLinkPage::initObjectList() */ protected function initObjectList() { parent::initObjectList(); $this->objectList->sqlSelects = "cronjob.*"; $this->objectList->sqlJoins = "LEFT JOIN wcf" . WCF_N . "_cronjob cronjob ON (cronjob.cronjobID = cronjob_log.cronjobID)"; $this->objectList->getConditionBuilder()->add("cronjob_log.cronjobID IN (SELECT cronjobID FROM wcf" . WCF_N . "_cronjob WHERE packageID IN (?))", array(PackageDependencyHandler::getInstance()->getDependencies())); }
/** * Loads storage for a given set of users. * * @param array<integer> $userIDs * @param integer $packageID */ public function loadStorage(array $userIDs, $packageID = PACKAGE_ID) { $tmp = array(); foreach ($userIDs as $userID) { if (!isset($this->cache[$userID])) { $tmp[] = $userID; } } // ignore users whose storage data is already loaded if (empty($tmp)) { return; } $conditions = new PreparedStatementConditionBuilder(); $conditions->add("userID IN (?)", array($tmp)); $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies($packageID))); $sql = "SELECT\t*\n\t\t\tFROM\twcf" . WCF_N . "_user_storage\n\t\t\t" . $conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); while ($row = $statement->fetchArray()) { if (!isset($this->cache[$row['userID']])) { $this->cache[$row['userID']] = array(); } $this->cache[$row['userID']][$row['field']] = $row['fieldValue']; } }
/** * @see wcf\system\cache\ICacheBuilder::getData() */ public function getData(array $cacheResource) { $actionList = new ClipboardActionList(); $actionList->getConditionBuilder()->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $actionList->sqlLimit = 0; $actionList->readObjects(); return $actionList->getObjects(); }
/** * @see wcf\system\cache\ICacheBuilder::getData() */ public function getData(array $cacheResource) { $sitemapList = new SitemapList(); $sitemapList->getConditionBuilder()->add("sitemap.packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $sitemapList->sqlLimit = 0; $sitemapList->sqlOrderBy = "sitemap.showOrder ASC"; $sitemapList->readObjects(); return $sitemapList->getObjects(); }
/** * @see wcf\system\cache\ICacheBuilder::getData() */ public function getData(array $cacheResource) { // get next execution time $conditionBuilder = new PreparedStatementConditionBuilder(); $conditionBuilder->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $sql = "SELECT\t\tMIN(nextExec) AS nextExec,\n\t\t\t\t\tMIN(afterNextExec) AS afterNextExec\n\t\t\tFROM\t\twcf" . WCF_N . "_cronjob\n\t\t\t" . $conditionBuilder->__toString(); $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); $row = $statement->fetchArray(); return array('afterNextExec' => $row['afterNextExec'], 'nextExec' => $row['nextExec']); }
/** * @see wcf\system\cache\ICacheBuilder::getData() */ public function getData(array $cacheResource) { $conditions = new PreparedStatementConditionBuilder(); $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $sql = "SELECT\tpageClassName, actionID\n\t\t\tFROM\twcf" . WCF_N . "_clipboard_page\n\t\t\t" . $conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); $data = array(); while ($row = $statement->fetchArray()) { if (!isset($data[$row['pageClassName']])) { $data[$row['pageClassName']] = array(); } $data[$row['pageClassName']][] = $row['actionID']; } return $data; }
/** * @see wcf\system\cache\ICacheBuilder::getData() */ public function getData(array $cacheResource) { list($packageID, $environment, $templateName) = explode('-', $cacheResource['cache']); // get template codes for specified template $templateListenerList = new TemplateListenerList(); $templateListenerList->getConditionBuilder()->add("template_listener.environment = ?", array($environment)); $templateListenerList->getConditionBuilder()->add("template_listener.templateName = ?", array($templateName)); $templateListenerList->getConditionBuilder()->add("template_listener.packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $templateListenerList->sqlLimit = 0; $templateListenerList->readObjects(); $data = array(); foreach ($templateListenerList->getObjects() as $templateListener) { $data[$templateListener->eventName][] = $templateListener->templateCode; } return $data; }
/** * @see wcf\system\cache\ICacheBuilder::getData() */ public function getData(array $cacheResource) { list($cache, $packageID, $environment) = explode('-', $cacheResource['cache']); // get templates for current package id $templateListenerList = new TemplateListenerList(); $templateListenerList->getConditionBuilder()->add("template_listener.environment = ?", array($environment)); // work-around during setup if (PACKAGE_ID) { $templateListenerList->getConditionBuilder()->add("template_listener.packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); } $templateListenerList->sqlLimit = 0; $templateListenerList->readObjects(); $data = array(); foreach ($templateListenerList->getObjects() as $templateListener) { $data[$templateListener->templateName] = array(); } return $data; }
/** * @see wcf\system\cache\ICacheBuilder::getData() */ public function getData(array $cacheResource) { $list = new CategoryList(); $list->sqlLimit = 0; $list->sqlSelects = "object_type.objectType"; $list->sqlJoins = "\tLEFT JOIN\twcf" . WCF_N . "_object_type object_type\n\t\t\t\t\tON\t\t(object_type.objectTypeID = category.objectTypeID)"; $list->getConditionBuilder()->add("object_type.packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $list->sqlOrderBy = "category.showOrder ASC"; $list->readObjects(); $data = array('categories' => $list->getObjects(), 'objectTypeCategoryIDs' => array()); foreach ($list as $category) { if (!isset($data['objectTypeCategoryIDs'][$category->objectType])) { $data['objectTypeCategoryIDs'][$category->objectType] = array(); } $data['objectTypeCategoryIDs'][$category->objectType][] = $category->categoryID; } return $data; }
/** * @see wcf\system\cache\ICacheBuilder::getData() */ public function getData(array $cacheResource) { list($cache, $packageID) = explode('-', $cacheResource['cache']); $data = array(); $coreObjectList = new CoreObjectList(); $coreObjectList->getConditionBuilder()->add("core_object.packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $coreObjectList->sqlLimit = 0; $coreObjectList->readObjects(); $coreObjects = $coreObjectList->getObjects(); foreach ($coreObjects as $coreObject) { if (!isset($data[$coreObject->packageID])) { $data[$coreObject->packageID] = array(); } $tmp = explode('\\', $coreObject->objectName); $className = array_pop($tmp); $data[$coreObject->packageID][$className] = $coreObject->objectName; } return $data; }
/** * @see wcf\action\IAction::execute() */ public function execute() { parent::execute(); // delete language cache and compiled templates as well LanguageFactory::getInstance()->deleteLanguageCache(); $conditions = new PreparedStatementConditionBuilder(); $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $conditions->add("isApplication = ?", array(1)); // get package dirs $sql = "SELECT\tpackageDir\n\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t" . $conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); while ($row = $statement->fetchArray()) { $packageDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']); try { CacheHandler::getInstance()->clear($packageDir . 'cache', '*.php'); } catch (SystemException $e) { } } $this->executed(); HeaderUtil::redirect(LinkHandler::getInstance()->getLink('CacheList')); exit; }
/** * @see wcf\page\IPage::readData() */ public function readData() { parent::readData(); // init cache data $this->cacheData = array('source' => get_class(CacheHandler::getInstance()->getCacheSource()), 'version' => '', 'size' => 0, 'files' => 0); $_this = $this; $readFileCache = function ($cacheDir, Regex $ignore = null) use($_this) { $_this->caches[$cacheDir] = array(); // get files in cache directory try { $directoryUtil = DirectoryUtil::getInstance($cacheDir); } catch (SystemException $e) { return; } $files = $directoryUtil->getFileObjects(SORT_ASC, new Regex('\\.php$')); // get additional file information if (is_array($files)) { foreach ($files as $file) { if ($ignore !== null) { if ($ignore->match($file)) { continue; } } $_this->caches[$cacheDir][] = array('filename' => $file->getBasename(), 'filesize' => $file->getSize(), 'mtime' => $file->getMtime(), 'perm' => substr(sprintf('%o', $file->getPerms()), -3), 'writable' => $file->isWritable()); $_this->cacheData['files']++; $_this->cacheData['size'] += $file->getSize(); } } }; // filesystem cache if ($this->cacheData['source'] == 'wcf\\system\\cache\\source\\DiskCacheSource') { // set version $this->cacheData['version'] = WCF_VERSION; $conditions = new PreparedStatementConditionBuilder(); $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $conditions->add("isApplication = ?", array(1)); // get package dirs $sql = "SELECT\tpackageDir\n\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t" . $conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); while ($row = $statement->fetchArray()) { $packageDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']); $readFileCache($packageDir . 'cache'); } } else { if ($this->cacheData['source'] == 'wcf\\system\\cache\\source\\MemcacheCacheSource') { // get version $this->cacheData['version'] = MemcacheAdapter::getInstance()->getMemcache()->getVersion(); // get stats $stats = MemcacheAdapter::getInstance()->getMemcache()->getStats(); $this->cacheData['files'] = $stats['curr_items']; $this->cacheData['size'] = $stats['bytes']; } else { if ($this->cacheData['source'] == 'wcf\\system\\cache\\source\\ApcCacheSource') { // set version $this->cacheData['version'] = phpversion('apc'); $conditions = new PreparedStatementConditionBuilder(); $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $conditions->add("isApplication = ?", array(1)); // get package dirs $sql = "SELECT\tpackageDir, packageName, instanceNo\n\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t" . $conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); $packageNames = array(); while ($row = $statement->fetchArray()) { $packagePath = FileUtil::getRealPath(WCF_DIR . $row['packageDir']) . 'cache/'; $packageNames[$packagePath] = $row['packageName'] . ' #' . $row['instanceNo']; } $apcinfo = apc_cache_info('user'); $cacheList = $apcinfo['cache_list']; foreach ($cacheList as $cache) { $cachePath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator(dirname($cache['info']))); if (isset($packageNames[$cachePath])) { // Use the packageName + the instance number, because pathes could confuse the administrator. // He could think this is a file cache. If instanceName would be unique, we could use it instead. $packageName = $packageNames[$cachePath]; if (!isset($this->caches[$packageName])) { $this->caches[$packageName] = array(); } // get additional cache information $this->caches[$packageName][] = array('filename' => basename($cache['info'], '.php'), 'filesize' => $cache['mem_size'], 'mtime' => $cache['mtime']); $this->cacheData['files']++; $this->cacheData['size'] += $cache['mem_size']; } } } else { if ($this->cacheData['source'] == 'wcf\\system\\cache\\source\\NoCacheSource') { $this->cacheData['version'] = WCF_VERSION; $this->cacheData['files'] = $this->cacheData['size'] = 0; } } } } $readFileCache(WCF_DIR . 'language'); $readFileCache(WCF_DIR . 'templates/compiled', new Regex('\\.meta\\.php$')); $readFileCache(WCF_DIR . 'acp/templates/compiled', new Regex('\\.meta\\.php$')); }
/** * Loads outstanding cronjobs. */ protected function loadCronjobs() { $conditions = new PreparedStatementConditionBuilder(); $conditions->add("cronjob.packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $conditions->add("(cronjob.nextExec <= ? OR cronjob.afterNextExec <= ?)", array(TIME_NOW, TIME_NOW)); $conditions->add("cronjob.active = ?", array(1)); $conditions->add("cronjob.failCount < ?", array(3)); $conditions->add("cronjob.state = ?", array(Cronjob::READY)); $sql = "SELECT\t\tcronjob.*\n\t\t\tFROM\t\twcf" . WCF_N . "_cronjob cronjob\n\t\t\t" . $conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); while ($row = $statement->fetchArray()) { $cronjob = new Cronjob(null, $row); $cronjobEditor = new CronjobEditor($cronjob); $executeCronjob = true; $data = array('state' => Cronjob::PENDING); // reset cronjob if it got stuck before and afterNextExec is in the past if ($cronjobEditor->afterNextExec <= TIME_NOW && $cronjobEditor->state == Cronjob::EXECUTING) { $failCount = $cronjobEditor->failCount + 1; $data['failCount'] = $failCount; // disable cronjob if ($failCount == 3) { $data['active'] = 0; $executeCronjob = false; } } else { if ($cronjobEditor->nextExec <= TIME_NOW && $cronjobEditor->state != Cronjob::READY) { $executeCronjob = false; } } // mark cronjob as pending, preventing parallel execution $cronjobEditor->update($data); if ($executeCronjob) { $this->cronjobEditors[] = $cronjobEditor; } } }
/** * Initializes core object cache. */ protected function initCoreObjects() { // ignore core objects if installing WCF if (PACKAGE_ID == 0) { return; } self::$coreObjectCache = CacheHandler::getInstance()->get('coreObjects-' . PACKAGE_ID); self::$packageDependencies = \wcf\system\package\PackageDependencyHandler::getInstance()->getDependencies(); }
/** * @see wcf\page\MultipleLinkPage::initObjectList() */ public function initObjectList() { parent::initObjectList(); $this->objectList->getConditionBuilder()->add("cronjob.packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $this->sqlOrderBy = "cronjob." . $this->sortField . " " . $this->sortOrder; }
/** * @see wcf\system\cache\ICacheBuilder::getData() */ public function getData(array $cacheResource) { list($cache, $packageID, $styleID) = explode('-', $cacheResource['cache']); $data = array(); // get active package $activePackage = new Package($packageID); $activePackageDir = FileUtil::getRealPath(WCF_DIR . $activePackage->packageDir); // get package dirs $packageDirs = array(); $conditionBuilder = new PreparedStatementConditionBuilder(); $conditionBuilder->add("dependency.packageID IN (?) AND package.packageDir <> ''", array(PackageDependencyHandler::getInstance()->getDependencies())); $sql = "SELECT\t\tDISTINCT package.packageDir, dependency.priority\n\t\t\tFROM\t\twcf" . WCF_N . "_package_dependency dependency\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\n\t\t\tON\t\t(package.packageID = dependency.dependency)\n\t\t\t" . $conditionBuilder->__toString() . "\n\t\t\tORDER BY\tdependency.priority DESC"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); while ($row = $statement->fetchArray()) { $packageDirs[] = FileUtil::getRealPath(WCF_DIR . $row['packageDir']); } $packageDirs[] = FileUtil::unifyDirSeperator(WCF_DIR); // get style icon path $iconDirs = array(); $sql = "SELECT\tvariableValue\n\t\t\tFROM\twcf" . WCF_N . "_style_variable\n\t\t\tWHERE\tstyleID = ?\n\t\t\t\tAND variableName = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($styleID, 'global.icons.location')); $row = $statement->fetchArray(); if (!empty($row['variableValue'])) { $iconDirs[] = FileUtil::addTrailingSlash($row['variableValue']); } if (!in_array('icon/', $iconDirs)) { $iconDirs[] = 'icon/'; } // get icons foreach ($packageDirs as $packageDir) { $relativePackageDir = $activePackageDir != $packageDir ? FileUtil::getRelativePath($activePackageDir, $packageDir) : ''; foreach ($iconDirs as $iconDir) { $path = FileUtil::addTrailingSlash($packageDir . $iconDir); // get png icons $icons = self::getIconFiles($path, 'png'); foreach ($icons as $icon) { $icon = str_replace($path, '', $icon); if (preg_match('/^(.*)(S|M|L)\\.png$/', $icon, $match)) { if (!isset($data[$match[1]][$match[2]])) { $data[$match[1]][$match[2]] = $relativePackageDir . $iconDir . $icon; } } } // get svg icons $icons = self::getIconFiles($path, 'svg'); foreach ($icons as $icon) { $icon = str_replace($path, '', $icon); if (preg_match('/^(.*)\\.svg$/', $icon, $match)) { if (!isset($data[$match[1]]['S'])) { $data[$match[1]]['S'] = $relativePackageDir . $iconDir . $icon; } if (!isset($data[$match[1]]['M'])) { $data[$match[1]]['M'] = $relativePackageDir . $iconDir . $icon; } if (!isset($data[$match[1]]['L'])) { $data[$match[1]]['L'] = $relativePackageDir . $iconDir . $icon; } } } } } return $data; }
/** * Searches in language items. * * @param string $search search query * @param string $replace * @param integer $languageID * @param boolean $useRegex * @param boolean $caseSensitive * @param boolean $searchVariableName * @return array results */ public static function search($search, $replace = null, $languageID = null, $useRegex = 0, $searchVariableName = 0) { $results = array(); // build condition $conditionBuilder = new PreparedStatementConditionBuilder(); // search field $statementParameters = array(); if ($searchVariableName) { $searchCondition = 'languageItem '; } else { $searchCondition = 'languageItemValue '; } // regex if ($useRegex) { $searchCondition .= "REGEXP ?"; $statementParameters[] = $search; } else { $searchCondition .= "LIKE ?"; $statementParameters[] = '%' . $search . '%'; } if (!$searchVariableName) { $searchCondition .= ' OR languageCustomItemValue '; // regex if ($useRegex) { $searchCondition .= "REGEXP ?"; $statementParameters[] = $search; } else { $searchCondition .= "LIKE ?"; $statementParameters[] = '%' . $search . '%'; } } $conditionBuilder->add($searchCondition, $statementParameters); $conditionBuilder->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); if ($languageID !== null) { $conditionBuilder->add("languageID = ?", array($languageID)); } // search $updatedItems = array(); $sql = "SELECT\t\t*\n\t\t\tFROM\t\twcf" . WCF_N . "_language_item\n\t\t\t" . $conditionBuilder; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); while ($row = $statement->fetchArray()) { if ($replace !== null) { // search and replace $matches = 0; if ($useRegex) { $newValue = preg_replace('~' . $search . '~s', $replace, $row['languageCustomItemValue'] ? $row['languageCustomItemValue'] : $row['languageItemValue'], -1, $matches); } else { $newValue = StringUtil::replaceIgnoreCase($search, $replace, $row['languageCustomItemValue'] ? $row['languageCustomItemValue'] : $row['languageItemValue'], $matches); } if ($matches > 0) { // update value if (!isset($updatedItems[$row['languageID']])) { $updatedItems[$row['languageID']] = array(); } if (!isset($updatedItems[$row['languageID']][$row['languageCategoryID']])) { $updatedItems[$row['languageID']][$row['languageCategoryID']] = array(); } $updatedItems[$row['languageID']][$row['languageCategoryID']][$row['languageItem']] = $newValue; // save matches $row['matches'] = $matches; } } $results[] = $row; } // save updates if (count($updatedItems) > 0) { foreach ($updatedItems as $languageID => $categories) { $language = new LanguageEditor($languageID); foreach ($categories as $categoryID => $items) { $useCustom = array(); foreach (array_keys($items) as $item) { $useCustom[$item] = 1; } $category = new LanguageCategory($categoryID); $language->updateItems($items, $category, PACKAGE_ID, $useCustom); } } } return $results; }