/**
  * @see	\wcf\system\setup\IFileHandler::logFiles()
  */
 public function logFiles(array $files)
 {
     // remove file extension
     foreach ($files as &$file) {
         $file = substr($file, 0, -4);
     }
     unset($file);
     // fetch already installed acp templates
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add('packageID = ?', array($this->packageInstallation->getPackageID()));
     $conditions->add('templateName IN (?)', array($files));
     $conditions->add('application = ?', array($this->application));
     $sql = "SELECT\ttemplateName\n\t\t\tFROM\twcf" . WCF_N . "_" . $this->tableName . "\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
     while ($templateName = $statement->fetchColumn()) {
         $index = array_search($templateName, $files);
         if ($index !== false) {
             unset($files[$index]);
         }
     }
     if (!empty($files)) {
         $sql = "INSERT INTO\twcf" . WCF_N . "_" . $this->tableName . "\n\t\t\t\t\t\t(packageID, templateName, application)\n\t\t\t\tVALUES\t\t(?, ?, ?)";
         $statement = WCF::getDB()->prepareStatement($sql);
         foreach ($files as $file) {
             $statement->execute(array($this->packageInstallation->getPackageID(), $file, $this->application));
         }
     }
 }
 /**
  * Reads associated tags.
  */
 protected function getTags()
 {
     $this->tags = array();
     if (!empty($this->objectTypeIDs)) {
         // get tag ids
         $tagIDs = array();
         $conditionBuilder = new PreparedStatementConditionBuilder();
         $conditionBuilder->add('object.objectTypeID IN (?)', array($this->objectTypeIDs));
         $conditionBuilder->add('object.languageID IN (?)', array($this->languageIDs));
         $sql = "SELECT\t\tCOUNT(*) AS counter, object.tagID\n\t\t\t\tFROM\t\twcf" . WCF_N . "_tag_to_object object\n\t\t\t\t" . $conditionBuilder . "\n\t\t\t\tGROUP BY\tobject.tagID\n\t\t\t\tORDER BY\tcounter DESC";
         $statement = WCF::getDB()->prepareStatement($sql, 500);
         $statement->execute($conditionBuilder->getParameters());
         while ($row = $statement->fetchArray()) {
             $tagIDs[$row['tagID']] = $row['counter'];
         }
         // get tags
         if (!empty($tagIDs)) {
             $sql = "SELECT\t*\n\t\t\t\t\tFROM\twcf" . WCF_N . "_tag\n\t\t\t\t\tWHERE\ttagID IN (?" . (count($tagIDs) > 1 ? str_repeat(',?', count($tagIDs) - 1) : '') . ")";
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute(array_keys($tagIDs));
             while ($row = $statement->fetchArray()) {
                 $row['counter'] = $tagIDs[$row['tagID']];
                 $this->tags[$row['name']] = new TagCloudTag(new Tag(null, $row));
             }
             // sort by counter
             uasort($this->tags, array('self', 'compareTags'));
         }
     }
 }
예제 #3
0
 /**
  * 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'];
     }
 }
예제 #4
0
 /**
  * @see	\wcf\system\setup\IFileHandler::checkFiles()
  */
 public function checkFiles(array $files)
 {
     if ($this->packageInstallation->getPackage()->package != 'com.woltlab.wcf') {
         if (!empty($files)) {
             // get registered files of other packages for the
             // same application
             $conditions = new PreparedStatementConditionBuilder();
             $conditions->add('packageID <> ?', array($this->packageInstallation->getPackageID()));
             $conditions->add('filename IN (?)', array($files));
             $conditions->add('application = ?', array($this->application));
             $sql = "SELECT\tfilename, packageID\n\t\t\t\t\tFROM\twcf" . WCF_N . "_package_installation_file_log\n\t\t\t\t\t" . $conditions;
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute($conditions->getParameters());
             $lockedFiles = array();
             while ($row = $statement->fetchArray()) {
                 $lockedFiles[$row['filename']] = $row['packageID'];
             }
             // check delivered files
             if (!empty($lockedFiles)) {
                 foreach ($files as $key => $file) {
                     if (isset($lockedFiles[$file])) {
                         $owningPackage = new Package($lockedFiles[$file]);
                         throw new SystemException("A package can't overwrite files from other packages. Only an update from the package which owns the file can do that. (Package '" . $this->packageInstallation->getPackage()->package . "' tries to overwrite file '" . $file . "', which is owned by package '" . $owningPackage->package . "')");
                     }
                 }
             }
         }
     }
 }
    protected function initUnreadArticle()
    {
        //Get application
        $classParts = explode('\\', get_called_class());
        if (WCF::getUser()->userID) {
            $conditionBuilder = new PreparedStatementConditionBuilder();
            $conditionBuilder->add(self::$articleType . '.lastChangeTime > ?', array(VisitTracker::getInstance()->getVisitTime(self::OBJECT_TYPE)));
            $conditionBuilder->add(self::$articleType . '.isDeleted = 0');
            $conditionBuilder->add(self::$articleType . '.isDisabled = 0');
            $conditionBuilder->add('tracked_visit.visitTime IS NULL');
            // apply language filter
            if (LanguageFactory::getInstance()->multilingualismEnabled() && count(WCF::getUser()->getLanguageIDs())) {
                $conditionBuilder->add('(' . self::$articleType . '.languageID IN (?) OR ' . self::$articleType . '.languageID IS NULL)', array(WCF::getUser()->getLanguageIDs()));
            }
            $sql = 'SELECT		COUNT(*) AS count, ' . self::$articleType . '_to_category.categoryID
				FROM		' . $classParts[0] . WCF_N . '_' . self::$articleType . ' ' . self::$articleType . '
				LEFT JOIN	wcf' . WCF_N . '_tracked_visit tracked_visit
				ON		(tracked_visit.objectTypeID = ' . VisitTracker::getInstance()->getObjectTypeID(self::OBJECT_TYPE) . ' AND tracked_visit.objectID = ' . self::$articleType . '.' . self::$articleType . 'ID AND tracked_visit.userID = ' . WCF::getUser()->userID . ')
				LEFT JOIN	' . $classParts[0] . WCF_N . '_' . self::$articleType . '_to_category ' . self::$articleType . '_to_category
				ON		(' . self::$articleType . '_to_category.' . self::$articleType . 'ID = ' . self::$articleType . '.' . self::$articleType . 'ID)
				' . $conditionBuilder . '
				GROUP BY	' . self::$articleType . '_to_category.categoryID';
            $statement = WCF::getDB()->prepareStatement($sql);
            $statement->execute($conditionBuilder->getParameters());
            while ($row = $statement->fetchArray()) {
                $this->unreadArticles[$row['categoryID']] = $row['count'];
            }
        }
    }
예제 #6
0
 /**
  * @see wcf\system\setup\IFileHandler::logFiles()
  */
 public function logFiles(array $files)
 {
     if (empty($files)) {
         return;
     }
     // fetch already installed files
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("packageID = ?", array($this->packageInstallation->getPackageID()));
     $conditions->add("filename IN (?)", array($files));
     $sql = "SELECT\tfilename\n\t\t\tFROM\twcf" . WCF_N . "_package_installation_file_log\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
     $installedFiles = array();
     while ($row = $statement->fetchArray()) {
         $installedFiles[] = $row['filename'];
     }
     // ignore files which have already been installed
     $installFiles = array();
     foreach ($files as $file) {
         if (in_array($file, $installedFiles)) {
             continue;
         }
         $installFiles[] = $file;
     }
     if (!empty($installFiles)) {
         $sql = "INSERT INTO\twcf" . WCF_N . "_package_installation_file_log\n\t\t\t\t\t\t(packageID, filename)\n\t\t\t\tVALUES\t\t(?, ?)";
         $statement = WCF::getDB()->prepareStatement($sql);
         foreach ($installFiles as $file) {
             $statement->execute(array($this->packageInstallation->getPackageID(), $file));
         }
     }
 }
예제 #7
0
 /**
  * @see wcf\system\cache\ICacheBuilder::getData()
  */
 public function getData(array $cacheResource)
 {
     list($cache, $packageID) = explode('-', $cacheResource['cache']);
     $data = array();
     // get all menu items and filter menu items with low priority
     $sql = "SELECT\t\tmenuItem, menuItemID \n\t\t\tFROM\t\twcf" . WCF_N . "_page_menu_item menu_item\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package_dependency package_dependency\n\t\t\tON\t\t(package_dependency.dependency = menu_item.packageID)\n\t\t\tWHERE \t\tpackage_dependency.packageID = ?\n\t\t\tORDER BY\tpackage_dependency.priority ASC";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array($packageID));
     $itemIDs = array();
     while ($row = $statement->fetchArray()) {
         $itemIDs[$row['menuItem']] = $row['menuItemID'];
     }
     if (count($itemIDs) > 0) {
         // get needed menu items and build item tree
         $conditions = new PreparedStatementConditionBuilder();
         $conditions->add("menu_item.menuItemID IN (?)", array($itemIDs));
         $conditions->add("menu_item.isDisabled = ?", array(0));
         $sql = "SELECT\t\tmenuItemID, menuItem, parentMenuItem, menuItemLink,\n\t\t\t\t\t\tpermissions, options, packageDir, menuPosition, className,\n\t\t\t\t\t\tCASE WHEN parentPackageID <> 0 THEN parentPackageID ELSE menu_item.packageID END AS packageID\n\t\t\t\tFROM\t\twcf" . WCF_N . "_page_menu_item menu_item\n\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\n\t\t\t\tON\t\t(package.packageID = menu_item.packageID)\n\t\t\t\t" . $conditions . "\n\t\t\t\tORDER BY\tshowOrder ASC";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute($conditions->getParameters());
         while ($row = $statement->fetchArray()) {
             $data[$row['parentMenuItem'] ? $row['parentMenuItem'] : $row['menuPosition']][] = new PageMenuItem(null, $row);
         }
     }
     return $data;
 }
예제 #8
0
 /**
  * @see	wcf\system\worker\IWorker::countObjects()
  */
 public function countObjects()
 {
     $this->conditions = new PreparedStatementConditionBuilder();
     $this->conditions->add("user.userID IN (?)", array($this->transferData['userIDs']));
     $sql = "SELECT\tCOUNT(*) AS count\n\t\t\tFROM\twcf" . WCF_N . "_user user\n\t\t\t" . $this->conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($this->conditions->getParameters());
     $row = $statement->fetchArray();
     $this->count = $row['count'];
 }
	/**
	 * @see	wcf\system\search\acp\IACPSearchResultProvider::search()
	 */
	public function search($query) {
		$results = array();
		
		// search by language item
		$conditions = new PreparedStatementConditionBuilder();
		$conditions->add("languageID = ?", array(WCF::getLanguage()->languageID));
		$conditions->add("languageItemValue LIKE ?", array($query.'%'));
		
		// filter by language item
		$languageItemsConditions = '';
		$languageItemsParameters = array();
		foreach (ACPSearchHandler::getInstance()->getAbbreviations('.acp.menu.link.%') as $abbreviation) {
			if (!empty($languageItemsConditions)) $languageItemsConditions .= " OR ";
			$languageItemsConditions .= "languageItem LIKE ?";
			$languageItemsParameters[] = $abbreviation;
		}
		$conditions->add("(".$languageItemsConditions.")", $languageItemsParameters);
		
		$sql = "SELECT		languageItem, languageItemValue
			FROM		wcf".WCF_N."_language_item
			".$conditions."
			ORDER BY	languageItemValue ASC";
		$statement = WCF::getDB()->prepareStatement($sql); // don't use a limit here
		$statement->execute($conditions->getParameters());
		$languageItems = array();
		while ($row = $statement->fetchArray()) {
			$languageItems[$row['languageItem']] = $row['languageItemValue'];
		}
		
		if (empty($languageItems)) {
			return array();
		}
		
		$conditions = new PreparedStatementConditionBuilder();
		$conditions->add("menuItem IN (?)", array(array_keys($languageItems)));
		$conditions->add("menuItemLink <> ''");
		
		$sql = "SELECT	menuItem, menuItemLink, permissions, options
			FROM	wcf".WCF_N."_acp_menu_item
			".$conditions;
		$statement = WCF::getDB()->prepareStatement($sql); // don't use a limit here
		$statement->execute($conditions->getParameters());
		
		while ($menuItem = $statement->fetchObject('wcf\data\acp\menu\item\ACPMenuItem')) {
			if (!$this->validate($menuItem)) {
				continue;
			}
			
			$results[] = new ACPSearchResult($languageItems[$menuItem->menuItem], $menuItem->getLink());
		}
		
		return $results;
	}
 /**
  * @see	\wcf\system\search\acp\IACPSearchResultProvider::search()
  */
 public function search($query)
 {
     $results = array();
     // search by language item
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("languageID = ?", array(WCF::getLanguage()->languageID));
     // filter by language item
     $languageItemsConditions = '';
     $languageItemsParameters = array();
     foreach (ACPSearchHandler::getInstance()->getAbbreviations('.acp.menu.link.%') as $abbreviation) {
         if (!empty($languageItemsConditions)) {
             $languageItemsConditions .= " OR ";
         }
         $languageItemsConditions .= "languageItem LIKE ?";
         $languageItemsParameters[] = $abbreviation;
     }
     $conditions->add("(" . $languageItemsConditions . ")", $languageItemsParameters);
     $conditions->add("languageItemValue LIKE ?", array('%' . $query . '%'));
     $sql = "SELECT\t\tlanguageItem, languageItemValue\n\t\t\tFROM\t\twcf" . WCF_N . "_language_item\n\t\t\t" . $conditions . "\n\t\t\tORDER BY\tlanguageItemValue ASC";
     $statement = WCF::getDB()->prepareStatement($sql);
     // don't use a limit here
     $statement->execute($conditions->getParameters());
     $languageItems = array();
     while ($row = $statement->fetchArray()) {
         $languageItems[$row['languageItem']] = $row['languageItemValue'];
     }
     if (empty($languageItems)) {
         return array();
     }
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("menuItem IN (?)", array(array_keys($languageItems)));
     $conditions->add("menuItemController <> ''");
     $sql = "SELECT\t*\n\t\t\tFROM\twcf" . WCF_N . "_acp_menu_item\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     // don't use a limit here
     $statement->execute($conditions->getParameters());
     $menuItems = ACPMenu::getInstance()->menuItemList;
     while ($menuItem = $statement->fetchObject('wcf\\data\\acp\\menu\\item\\ACPMenuItem')) {
         // only valid menu items exist in TreeMenu::$menuItemList,
         // so no need to call AbstractACPSearchResultProvider::validate()
         if (!isset($menuItems[$menuItem->menuItem])) {
             continue;
         }
         $parentMenuItem = $menuItem->parentMenuItem;
         $parentMenuItems = array();
         while ($parentMenuItem && isset($menuItems[$parentMenuItem])) {
             array_unshift($parentMenuItems, $parentMenuItem);
             $parentMenuItem = $menuItems[$parentMenuItem]->parentMenuItem;
         }
         $results[] = new ACPSearchResult($languageItems[$menuItem->menuItem], $menuItem->getLink(), WCF::getLanguage()->getDynamicVariable('wcf.acp.search.result.subtitle', array('pieces' => $parentMenuItems)));
     }
     return $results;
 }
 /**
  * @see	\wcf\system\worker\IWorker::execute()
  */
 public function execute()
 {
     parent::execute();
     if (!count($this->objectList)) {
         return;
     }
     if (!$this->loopCount) {
         // remove the activity points
         UserActivityPointHandler::getInstance()->reset('de.voolia.news.activityPointEvent.news');
         // remove the entry from search index
         SearchIndexManager::getInstance()->reset('de.voolia.news.entry');
     }
     // get news attachments
     $attachmentObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.attachment.objectType', 'de.voolia.news.entry');
     $sql = "SELECT\t\tCOUNT(*) AS attachments\n\t\t\tFROM\t\twcf" . WCF_N . "_attachment\n\t\t\tWHERE\t\tobjectTypeID = ?\n\t\t\tAND\t\tobjectID = ?";
     $attachments = WCF::getDB()->prepareStatement($sql);
     // calculate the cumulative likes
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("objectID IN (?)", array($this->objectList->getObjectIDs()));
     $conditions->add("objectTypeID = ?", array(ObjectTypeCache::getInstance()->getObjectTypeIDByName('com.woltlab.wcf.like.likeableObject', 'de.voolia.news.likeableNews')));
     $sql = "SELECT\tobjectID,\n\t\t\t\tcumulativeLikes\n\t\t\tFROM\twcf" . WCF_N . "_like_object\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
     $likes = array();
     while ($row = $statement->fetchArray()) {
         $likes[$row['objectID']] = $row['cumulativeLikes'];
     }
     // update the news entries
     $userItems = array();
     foreach ($this->objectList as $news) {
         // new EntryEditor
         $editor = new NewsEditor($news);
         // update search index
         SearchIndexManager::getInstance()->add('de.voolia.news.entry', $news->newsID, $news->message, $news->subject, $news->time, $news->userID, $news->username, $news->languageID);
         // news data
         $newsData = array();
         // likes
         $newsData['cumulativeLikes'] = isset($likes[$news->newsID]) ? $likes[$news->newsID] : 0;
         // attachments
         $attachments->execute(array($attachmentObjectType->objectTypeID, $news->newsID));
         $row = $attachments->fetchArray();
         $newsData['attachments'] = $row['attachments'];
         if ($news->userID) {
             if (!isset($userItems[$news->userID])) {
                 $userItems[$news->userID] = 0;
             }
             $userItems[$news->userID]++;
         }
         $editor->update($newsData);
     }
     // update activity points
     UserActivityPointHandler::getInstance()->fireEvents('de.voolia.news.activityPointEvent.news', $userItems, false);
 }
 /**
  * @see wcf\system\cache\ICacheBuilder::getData()
  */
 public function getData(array $cacheResource)
 {
     list($cache, $packageID, $groupIDs) = explode('-', $cacheResource['cache']);
     $data = array();
     // get all options and filter options with low priority
     if ($packageID == 0) {
         // during the installation of the package wcf
         $sql = "SELECT\t\toptionName, optionID \n\t\t\t\tFROM\t\twcf" . WCF_N . "_user_group_option\n\t\t\t\tWHERE \t\tpackageID IS NULL";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute();
     } else {
         $sql = "SELECT\t\toptionName, optionID \n\t\t\t\tFROM\t\twcf" . WCF_N . "_user_group_option option_table\n\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_package_dependency package_dependency\n\t\t\t\tON\t\t(package_dependency.dependency = option_table.packageID)\n\t\t\t\tWHERE \t\tpackage_dependency.packageID = ?\n\t\t\t\tORDER BY\tpackage_dependency.priority ASC";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($packageID));
     }
     $options = array();
     while ($row = $statement->fetchArray()) {
         $options[$row['optionName']] = $row['optionID'];
     }
     if (count($options) > 0) {
         // get needed options
         $conditions = new PreparedStatementConditionBuilder();
         $conditions->add("option_value.groupID IN (?)", array(explode(',', $groupIDs)));
         $conditions->add("option_value.optionID IN (?)", array($options));
         $sql = "SELECT\t\toption_table.optionName, option_table.optionType, option_value.optionValue\n\t\t\t\tFROM\t\twcf" . WCF_N . "_user_group_option_value option_value\n\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_group_option option_table\n\t\t\t\tON\t\t(option_table.optionID = option_value.optionID)\n\t\t\t\t" . $conditions;
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute($conditions->getParameters());
         while ($row = $statement->fetchArray()) {
             if (!isset($data[$row['optionName']])) {
                 $data[$row['optionName']] = array('type' => $row['optionType'], 'values' => array());
             }
             $data[$row['optionName']]['values'][] = $row['optionValue'];
         }
         // merge values
         foreach ($data as $optionName => $option) {
             if (count($option['values']) == 1) {
                 $result = $option['values'][0];
             } else {
                 $typeObj = $this->getTypeObject($option['type']);
                 $result = $typeObj->merge($option['values']);
             }
             // unset false values
             if ($result === false) {
                 unset($data[$optionName]);
             } else {
                 $data[$optionName] = $result;
             }
         }
     }
     $data['groupIDs'] = $groupIDs;
     return $data;
 }
예제 #13
0
 /**
  * @see	\wcf\system\option\ISearchableUserOption::getCondition()
  */
 public function getCondition(PreparedStatementConditionBuilder &$conditions, Option $option, $value)
 {
     if (!isset($_POST['searchOptions'][$option->optionName])) {
         return false;
     }
     $value = StringUtil::trim($value);
     if ($value == '') {
         $conditions->add("option_value.userOption" . $option->optionID . " = ?", array(''));
     } else {
         $conditions->add("option_value.userOption" . $option->optionID . " LIKE ?", array('%' . addcslashes($value, '_%') . '%'));
     }
     return true;
 }
 /**
  * Removes log entries.
  * 
  * @param	string		$objectType
  * @param	array<integer>	$objectIDs
  */
 protected function _remove($objectType, array $objectIDs)
 {
     $objectType = $this->getObjectType($objectType);
     if ($objectType === null) {
         throw new SystemException("Object type '" . $objectType . "' not found within definition 'com.woltlab.wcf.modifiableContent'");
     }
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("objectTypeID = ?", array($objectType->objectTypeID));
     $conditions->add("objectID IN (?)", array($objectIDs));
     $sql = "DELETE FROM\twcf" . WCF_N . "_modification_log\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
 }
 /**
  * @see	\wcf\system\worker\IWorker::execute()
  */
 public function execute()
 {
     parent::execute();
     if (!$this->loopCount) {
         // reset activity points
         UserActivityPointHandler::getInstance()->reset('de.incendium.linklist.activityPointEvent.entry');
         // reset search index
         SearchIndexManager::getInstance()->reset('de.incendium.linklist.entry');
     }
     if (!count($this->objectList)) {
         return;
     }
     // fetch cumulative likes
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("objectTypeID = ?", array(ObjectTypeCache::getInstance()->getObjectTypeIDByName('com.woltlab.wcf.like.likeableObject', 'de.incendium.linklist.likeableEntry')));
     $conditions->add("objectID IN (?)", array($this->objectList->getObjectIDs()));
     $sql = "SELECT\tobjectID, cumulativeLikes\n\t\t\tFROM\twcf" . WCF_N . "_like_object\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
     $cumulativeLikes = array();
     while ($row = $statement->fetchArray()) {
         $cumulativeLikes[$row['objectID']] = $row['cumulativeLikes'];
     }
     // prepare statements
     $attachmentObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.attachment.objectType', 'de.incendium.linklist.entry');
     $sql = "SELECT\t\tCOUNT(*) AS attachments\n\t\t\tFROM\t\twcf" . WCF_N . "_attachment\n\t\t\tWHERE\t\tobjectTypeID = ?\n\t\t\t\t\tAND objectID = ?";
     $attachmentStatement = WCF::getDB()->prepareStatement($sql);
     $itemsToUser = array();
     foreach ($this->objectList as $entry) {
         $editor = new EntryEditor($entry);
         $data = array();
         // count attachments
         $attachmentStatement->execute(array($attachmentObjectType->objectTypeID, $entry->entryID));
         $row = $attachmentStatement->fetchArray();
         $data['attachments'] = $row['attachments'];
         // update cumulative likes
         $data['cumulativeLikes'] = isset($cumulativeLikes[$entry->entryID]) ? $cumulativeLikes[$entry->entryID] : 0;
         $editor->update($data);
         if ($entry->userID) {
             if (!isset($itemsToUser[$entry->userID])) {
                 $itemsToUser[$entry->userID] = 0;
             }
             $itemsToUser[$entry->userID]++;
         }
         // update search index
         SearchIndexManager::getInstance()->add('de.incendium.linklist.entry', $entry->entryID, $entry->message, $entry->subject, $entry->time, $entry->userID, $entry->username, $entry->languageID);
     }
     // update activity points
     UserActivityPointHandler::getInstance()->fireEvents('de.incendium.linklist.activityPointEvent.entry', $itemsToUser, false);
 }
 /**
  * @see	\wcf\system\cache\builder\AbstractCacheBuilder::rebuild()
  */
 public function rebuild(array $parameters)
 {
     $data = array();
     // get all options
     $sql = "SELECT\toptionName, optionID\n\t\t\tFROM\twcf" . WCF_N . "_user_group_option";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute();
     $options = array();
     while ($row = $statement->fetchArray()) {
         $options[$row['optionName']] = $row['optionID'];
     }
     if (!empty($options)) {
         // get needed options
         $conditions = new PreparedStatementConditionBuilder();
         $conditions->add("option_value.groupID IN (?)", array($parameters));
         $conditions->add("option_value.optionID IN (?)", array($options));
         $sql = "SELECT\t\toption_table.optionName, option_table.optionType, option_value.optionValue\n\t\t\t\tFROM\t\twcf" . WCF_N . "_user_group_option_value option_value\n\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_group_option option_table\n\t\t\t\tON\t\t(option_table.optionID = option_value.optionID)\n\t\t\t\t" . $conditions;
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute($conditions->getParameters());
         while ($row = $statement->fetchArray()) {
             if (!isset($data[$row['optionName']])) {
                 $data[$row['optionName']] = array('type' => $row['optionType'], 'values' => array());
             }
             $data[$row['optionName']]['values'][] = $row['optionValue'];
         }
         // merge values
         foreach ($data as $optionName => $option) {
             if (count($option['values']) == 1) {
                 $result = $option['values'][0];
             } else {
                 $typeObj = $this->getTypeObject($option['type']);
                 $result = array_shift($option['values']);
                 foreach ($option['values'] as $value) {
                     $newValue = $typeObj->merge($result, $value);
                     if ($newValue !== null) {
                         $result = $newValue;
                     }
                 }
             }
             // unset false values
             if ($result === false) {
                 unset($data[$optionName]);
             } else {
                 $data[$optionName] = $result;
             }
         }
     }
     $data['groupIDs'] = $parameters;
     return $data;
 }
 /**
  * @see	\wcf\system\faker\AbstractFaker::__construct()
  */
 public function __construct(\Faker\Generator $generator, array $parameters)
 {
     parent::__construct($generator, $parameters);
     $this->condition = new \wcf\system\database\util\PreparedStatementConditionBuilder();
     if (isset($this->parameters['objectTypeIDs']) && !empty($this->parameters['objectTypeIDs'])) {
         $this->condition->add('objectTypeID IN(?)', array($this->parameters['objectTypeIDs']));
     } else {
         $this->condition->add('1=1');
     }
     $sql = "SELECT\tCOUNT(*)\n\t\t\tFROM\twcf" . WCF_N . "_comment\n\t\t\t" . $this->condition;
     $statement = \wcf\system\WCF::getDB()->prepareStatement($sql);
     $statement->execute($this->condition->getParameters());
     $this->commentCount = $statement->fetchColumn();
 }
 /**
  * Deletes the given objects.
  * 
  * @param	string		$objectType
  * @param	array<integer>	$objectIDs
  * @param	array<integer>	$userIDs
  */
 public function deleteObjects($objectType, array $objectIDs, array $userIDs = array())
 {
     // get object type id
     $objectTypeObj = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.user.objectWatch', $objectType);
     // delete objects
     $conditionsBuilder = new PreparedStatementConditionBuilder();
     $conditionsBuilder->add('objectTypeID = ?', array($objectTypeObj->objectTypeID));
     $conditionsBuilder->add('objectID IN (?)', array($objectIDs));
     if (!empty($userIDs)) {
         $conditionsBuilder->add('userID IN (?)', array($userIDs));
     }
     $sql = "DELETE FROM\twcf" . WCF_N . "_user_object_watch\n\t\t\t" . $conditionsBuilder;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditionsBuilder->getParameters());
 }
 /**
  * @see	\wcf\system\like\IViewableLikeProvider::prepare()
  */
 public function prepare(array $likes)
 {
     $responseIDs = array();
     foreach ($likes as $like) {
         $responseIDs[] = $like->objectID;
     }
     // get objects type ids
     $responses = array();
     $conditionBuilder = new PreparedStatementConditionBuilder();
     $conditionBuilder->add('comment_response.responseID IN (?)', array($responseIDs));
     $sql = "SELECT\t\tcomment.objectTypeID, comment_response.responseID\n\t\t\tFROM\t\twcf" . WCF_N . "_comment_response comment_response\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_comment comment\n\t\t\tON\t\t(comment.commentID = comment_response.commentID)\n\t\t\t" . $conditionBuilder;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditionBuilder->getParameters());
     while ($row = $statement->fetchArray()) {
         $responses[$row['responseID']] = $row['objectTypeID'];
     }
     // group likes by object type id
     $likeData = array();
     foreach ($likes as $like) {
         if (isset($responses[$like->objectID])) {
             if (!isset($likeData[$responses[$like->objectID]])) {
                 $likeData[$responses[$like->objectID]] = array();
             }
             $likeData[$responses[$like->objectID]][] = $like;
         }
     }
     foreach ($likeData as $objectTypeID => $likes) {
         $objectType = CommentHandler::getInstance()->getObjectType($objectTypeID);
         if (CommentHandler::getInstance()->getCommentManager($objectType->objectType) instanceof IViewableLikeProvider) {
             CommentHandler::getInstance()->getCommentManager($objectType->objectType)->prepare($likes);
         }
     }
 }
예제 #20
0
 /**
  * @see	wcf\system\worker\IWorker::countObjects()
  */
 public function countObjects()
 {
     $this->conditions = new PreparedStatementConditionBuilder();
     if ($this->mailData['action'] == '') {
         $this->conditions->add("user.userID IN (?)", array($this->mailData['userIDs']));
     } else {
         if ($this->mailData['action'] == 'group') {
             $this->conditions->add("user.userID IN (SELECT userID FROM wcf" . WCF_N . "_user_to_group WHERE groupID IN (?))", array($this->mailData['groupIDs']));
         }
     }
     $sql = "SELECT\tCOUNT(*) AS count\n\t\t\tFROM\twcf" . WCF_N . "_user user\n\t\t\t" . $this->conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($this->conditions->getParameters());
     $row = $statement->fetchArray();
     $this->count = $row['count'];
 }
예제 #21
0
	/**
	 * @see	wcf\system\option\ISearchableUserOption::getCondition()
	 */
	public function getCondition(PreparedStatementConditionBuilder &$conditions, Option $option, $value) {
		$value = StringUtil::trim($value);
		if (empty($value)) return false;
		
		$conditions->add("option_value.userOption".$option->optionID." LIKE ?", array('%'.addcslashes($value, '_%').'%'));
		return true;
	}
예제 #22
0
 protected function getTopOptionCategories($packageID)
 {
     // get all option categories and filter categories with low priority
     $sql = "SELECT\t\tcategoryName, categoryID \n\t\t\tFROM\t\twcf" . WCF_N . "_option_category option_category\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package_dependency package_dependency\n\t\t\tON\t\t(package_dependency.dependency = option_category.packageID)\n\t\t\tWHERE \t\tpackage_dependency.packageID = ?\n\t\t\tORDER BY\tpackage_dependency.priority ASC";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array($packageID));
     $optionCategories = array();
     while ($row = $statement->fetchArray()) {
         $optionCategories[$row['categoryName']] = $row['categoryID'];
     }
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("categoryID IN (?)", array($optionCategories));
     $statementParameters = $conditions->getParameters();
     array_unshift($statementParameters, $packageID);
     $sql = "SELECT \t\tcategoryID, parentCategoryName, categoryName,\n\t\t\t\t\t(\n\t\t\t\t\t\tSELECT COUNT(*) FROM wcf" . WCF_N . "_option WHERE categoryName = category.categoryName AND packageID IN (\n\t\t\t\t\t\t\tSELECT dependency FROM wcf" . WCF_N . "_package_dependency WHERE packageID = ?\n\t\t\t\t\t\t)\n\t\t\t\t\t) AS count\n\t\t\tFROM\t\twcf" . WCF_N . "_option_category category\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($statementParameters);
     while ($row = $statement->fetchArray()) {
         if (!isset($this->optionCategoryStructure[$row['parentCategoryName']])) {
             $this->optionCategoryStructure[$row['parentCategoryName']] = array();
         }
         $this->optionCategoryStructure[$row['parentCategoryName']][] = $row;
     }
     $topOptionCategories = array();
     foreach ($this->optionCategoryStructure[''] as $optionCategory) {
         $count = $optionCategory['count'] + $this->countOptions($optionCategory['categoryName']);
         if ($count > 0) {
             $topOptionCategories[] = $optionCategory['categoryID'];
         }
     }
     return $topOptionCategories;
 }
 /**
  * @see	\wcf\system\event\listener\IParameterizedEventListener::execute()
  */
 public function execute($eventObj, $className, $eventName, array &$parameters)
 {
     // conversation
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("userID IN (?)", array($eventObj->mergedUserIDs));
     $sql = "UPDATE\twcf" . WCF_N . "_conversation\n\t\t\tSET\tuserID = ?\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array_merge(array($eventObj->destinationUserID), $conditions->getParameters()));
     // conversation_to_user
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("participantID IN (?)", array($eventObj->mergedUserIDs));
     $sql = "UPDATE IGNORE\twcf" . WCF_N . "_conversation_to_user\n\t\t\tSET\t\tparticipantID = ?\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array_merge(array($eventObj->destinationUserID), $conditions->getParameters()));
     // conversation_message
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("userID IN (?)", array($eventObj->mergedUserIDs));
     $sql = "UPDATE\twcf" . WCF_N . "_conversation_message\n\t\t\tSET\tuserID = ?\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array_merge(array($eventObj->destinationUserID), $conditions->getParameters()));
     // conversation_label
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("userID IN (?)", array($eventObj->mergedUserIDs));
     $sql = "UPDATE\twcf" . WCF_N . "_conversation_label\n\t\t\tSET\tuserID = ?\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array_merge(array($eventObj->destinationUserID), $conditions->getParameters()));
 }
 /**
  * @see	\wcf\system\moderation\queue\IModerationQueueHandler::assignQueues()
  */
 public function assignQueues(array $queues)
 {
     $assignments = array();
     // read comments and responses
     $responseIDs = array();
     foreach ($queues as $queue) {
         $responseIDs[] = $queue->objectID;
     }
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("comment_response.responseID IN (?)", array($responseIDs));
     $sql = "SELECT\t\tcomment_response.responseID, comment.commentID, comment.objectTypeID, comment.objectID\n\t\t\tFROM\t\twcf" . WCF_N . "_comment_response comment_response\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_comment comment\n\t\t\tON\t\t(comment.commentID = comment_response.commentID)\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
     $comments = $responses = array();
     while ($row = $statement->fetchArray()) {
         $comments[$row['commentID']] = new Comment(null, $row);
         $responses[$row['responseID']] = new CommentResponse(null, $row);
     }
     $orphanedQueueIDs = array();
     foreach ($queues as $queue) {
         $assignUser = false;
         if (!isset($responses[$queue->objectID]) || !isset($comments[$responses[$queue->objectID]->commentID])) {
             $orphanedQueueIDs[] = $queue->queueID;
             continue;
         }
         $comment = $comments[$responses[$queue->objectID]->commentID];
         if ($this->getCommentManager($comment)->canModerate($comment->objectTypeID, $comment->objectID)) {
             $assignUser = true;
         }
         $assignments[$queue->queueID] = $assignUser;
     }
     ModerationQueueManager::getInstance()->removeOrphans($orphanedQueueIDs);
     ModerationQueueManager::getInstance()->setAssignment($assignments);
 }
 /**
  * @see	\wcf\system\worker\IWorker::execute()
  */
 public function execute()
 {
     parent::execute();
     $users = $userIDs = array();
     foreach ($this->getObjectList() as $user) {
         $users[] = new UserEditor($user);
         $userIDs[] = $user->userID;
     }
     // update user ranks
     if (!empty($users)) {
         $action = new UserProfileAction($users, 'updateUserOnlineMarking');
         $action->executeAction();
     }
     if (!empty($userIDs)) {
         // update activity points
         UserActivityPointHandler::getInstance()->updateUsers($userIDs);
         // update like counter
         if (MODULE_LIKE) {
             $conditionBuilder = new PreparedStatementConditionBuilder();
             $conditionBuilder->add('user_table.userID IN (?)', array($userIDs));
             $sql = "UPDATE\twcf" . WCF_N . "_user user_table\n\t\t\t\t\tSET\tlikesReceived = (\n\t\t\t\t\t\t\tSELECT\tCOUNT(*)\n\t\t\t\t\t\t\tFROM\twcf" . WCF_N . "_like\n\t\t\t\t\t\t\tWHERE\tobjectUserID = user_table.userID\n\t\t\t\t\t\t\t\tAND likeValue = " . Like::LIKE . "\n\t\t\t\t\t\t)\n\t\t\t\t\t" . $conditionBuilder;
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute($conditionBuilder->getParameters());
         }
     }
 }
 /**
  * Updates the participants of this conversation.
  * 
  * @param	array<integer>	$participantIDs
  * @param	array<integer>	$invisibleParticipantIDs
  */
 public function updateParticipants(array $participantIDs, array $invisibleParticipantIDs = array())
 {
     $usernames = array();
     if (!empty($participantIDs) || !empty($invisibleParticipantIDs)) {
         $conditions = new PreparedStatementConditionBuilder();
         $conditions->add("userID IN (?)", array(array_merge($participantIDs, $invisibleParticipantIDs)));
         $sql = "SELECT\tuserID, username\n\t\t\t\tFROM\twcf" . WCF_N . "_user\n\t\t\t\t" . $conditions;
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute($conditions->getParameters());
         while ($row = $statement->fetchArray()) {
             $usernames[$row['userID']] = $row['username'];
         }
     }
     if (!empty($participantIDs)) {
         WCF::getDB()->beginTransaction();
         $sql = "INSERT INTO\t\twcf" . WCF_N . "_conversation_to_user\n\t\t\t\t\t\t\t(conversationID, participantID, username, isInvisible)\n\t\t\t\tVALUES\t\t\t(?, ?, ?, ?)\n\t\t\t\tON DUPLICATE KEY\n\t\t\t\tUPDATE\t\t\thideConversation = 0";
         $statement = WCF::getDB()->prepareStatement($sql);
         foreach ($participantIDs as $userID) {
             $statement->execute(array($this->conversationID, $userID, $usernames[$userID], 0));
         }
         WCF::getDB()->commitTransaction();
     }
     if (!empty($invisibleParticipantIDs)) {
         WCF::getDB()->beginTransaction();
         $sql = "INSERT INTO\t\twcf" . WCF_N . "_conversation_to_user\n\t\t\t\t\t\t\t(conversationID, participantID, username, isInvisible)\n\t\t\t\tVALUES\t\t\t(?, ?, ?, ?)";
         $statement = WCF::getDB()->prepareStatement($sql);
         foreach ($invisibleParticipantIDs as $userID) {
             $statement->execute(array($this->conversationID, $userID, $usernames[$userID], 1));
         }
         WCF::getDB()->commitTransaction();
     }
     $this->updateParticipantCount();
 }
예제 #27
0
 /**
  * @see	\wcf\data\ISortableAction::validateUpdatePosition()
  */
 public function validateUpdatePosition()
 {
     if (!WCF::getSession()->getPermission('admin.project.canEditProject')) {
         throw new PermissionDeniedException();
     }
     if (!isset($this->parameters['data']['structure'])) {
         throw new UserInputException('structure');
     }
     $projectIDs = array();
     foreach ($this->parameters['data']['structure'][0] as $projectID) {
         if (!$projectID) {
             throw new UserInputException('structure');
         }
         $projectIDs[] = $projectID;
     }
     $projectIDs = array_unique($projectIDs);
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("projectID IN (?)", array($projectIDs));
     $sql = "SELECT\tprojectID\n\t\t\t\tFROM\tict" . WCF_N . "_project\n\t\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
     while ($row = $statement->fetchArray()) {
         $key = array_search($row['projectID'], $projectIDs);
         if ($key !== false) {
             unset($projectIDs[$key]);
         }
     }
     if (!empty($projectIDs)) {
         throw new UserInputException('structure');
     }
 }
 /**
  * @see	\wcf\system\search\acp\IACPSearchResultProvider::search()
  */
 public function search($query)
 {
     if (!WCF::getSession()->getPermission('admin.system.package.canUpdatePackage') && !WCF::getSession()->getPermission('admin.system.package.canUninstallPackage')) {
         return array();
     }
     $results = array();
     // search by language item
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("languageID = ?", array(WCF::getLanguage()->languageID));
     $conditions->add("languageItem LIKE ?", array('wcf.acp.package.packageName.package%'));
     $conditions->add("languageItemValue LIKE ?", array('%' . $query . '%'));
     $sql = "SELECT\t\tlanguageItem\n\t\t\tFROM\t\twcf" . WCF_N . "_language_item\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
     $packageIDs = array();
     while ($row = $statement->fetchArray()) {
         $packageIDs[] = str_replace('wcf.acp.package.packageName.package', '', $row['languageItem']);
     }
     $conditions = new PreparedStatementConditionBuilder(false);
     if (!empty($packageIDs)) {
         $conditions->add("packageID IN (?)", array($packageIDs));
     }
     $sql = "SELECT\t*\n\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\tWHERE\tpackageName LIKE ?\n\t\t\t\tOR package LIKE ?\n\t\t\t\t" . (count($conditions->getParameters()) ? "OR " . $conditions : "");
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array_merge(array($query . '%', $query . '%'), $conditions->getParameters()));
     while ($package = $statement->fetchObject('wcf\\data\\package\\Package')) {
         $results[] = new ACPSearchResult($package->getName(), LinkHandler::getInstance()->getLink('Package', array('id' => $package->packageID, 'title' => $package->getName())));
     }
     return $results;
 }
 /**
  * @see	\wcf\system\cache\builder\AbstractCacheBuilder::rebuild()
  */
 protected function rebuild(array $parameters)
 {
     $data = array('boxes' => array(), 'pages' => array());
     // load boxes
     $boxList = new DashboardBoxList();
     $boxList->readObjects();
     foreach ($boxList as $box) {
         $data['boxes'][$box->boxID] = $box;
     }
     // load settings
     $objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.user.dashboardContainer');
     $objectTypeIDs = array();
     foreach ($objectTypes as $objectType) {
         $objectTypeIDs[] = $objectType->objectTypeID;
     }
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("objectTypeID IN (?)", array($objectTypeIDs));
     $sql = "SELECT\t\t*\n\t\t\tFROM\t\twcf" . WCF_N . "_dashboard_option\n\t\t\t" . $conditions . "\n\t\t\tORDER BY\tshowOrder ASC";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
     while ($row = $statement->fetchArray()) {
         if (!isset($data['pages'][$row['objectTypeID']])) {
             $data['pages'][$row['objectTypeID']] = array();
         }
         $data['pages'][$row['objectTypeID']][] = $row['boxID'];
     }
     return $data;
 }
예제 #30
0
 /**
  * @see	\wcf\system\setup\IFileHandler::logFiles()
  */
 public function logFiles(array $files)
 {
     $packageID = $this->packageInstallation->getPackageID();
     // remove file extension
     foreach ($files as &$file) {
         $file = substr($file, 0, -4);
     }
     unset($file);
     // get existing templates
     $existingTemplates = $updateTemplateIDs = array();
     $sql = "SELECT\ttemplateName, templateID\n\t\t\tFROM\twcf" . WCF_N . "_template\n\t\t\tWHERE\tpackageID = ?\n\t\t\t\tAND application = ?\n\t\t\t\tAND templateGroupID IS NULL";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array($packageID, $this->application));
     while ($row = $statement->fetchArray()) {
         $existingTemplates[$row['templateName']] = $row['templateID'];
     }
     // save new templates
     $sql = "INSERT INTO\twcf" . WCF_N . "_template\n\t\t\t\t\t(packageID, templateName, lastModificationTime, application)\n\t\t\tVALUES\t\t(?, ?, ?, ?)";
     $statement = WCF::getDB()->prepareStatement($sql);
     foreach ($files as $file) {
         if (isset($existingTemplates[$file])) {
             $updateTemplateIDs[] = $existingTemplates[$file];
             continue;
         }
         $statement->execute(array($packageID, $file, TIME_NOW, $this->application));
     }
     if (!empty($updateTemplateIDs)) {
         // update old templates
         $conditionBuilder = new PreparedStatementConditionBuilder();
         $conditionBuilder->add('templateID IN (?)', array($updateTemplateIDs));
         $sql = "UPDATE\twcf" . WCF_N . "_template\n\t\t\t\tSET\tlastModificationTime = ?\n\t\t\t\t" . $conditionBuilder;
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array_merge(array(TIME_NOW), $conditionBuilder->getParameters()));
     }
 }