Esempio n. 1
0
 public static function initiate($method, array $args)
 {
     if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50307) {
         throw new GFNCore_Exception('This add-on does not support PHP versions lesser than 5.3.7', true);
     }
     if ($method == 'install' && !empty($args[0])) {
         $job = 'upgrade';
     } else {
         $job = $method;
     }
     /** @var GFNCore_Installer_Abstract $obj */
     $obj = new static();
     $obj->setJob($job);
     if ($method == 'install') {
         $obj->setNewData($args[1]);
         $obj->setXml($args[2]);
     }
     if (in_array($job, array('upgrade', 'uninstall'))) {
         $obj->setExistingData($args[0]);
     }
     $class = 'GFNCore_Installer_Controller_' . ucfirst($job);
     XenForo_Db::beginTransaction();
     try {
         /** @var GFNCore_Installer_Controller_Abstract $controller */
         $controller = new $class($obj);
         $controller->execute();
     } catch (Exception $e) {
         XenForo_Db::rollback();
         throw $e;
     }
     XenForo_Db::commit();
     $style = new GFNCore_Installer_Handler_Style();
     $style->handle($obj->getData()->addon_id);
 }
Esempio n. 2
0
 /**
  * Rebuilds the data.
  *
  * @see XenForo_CacheRebuilder_Abstract::rebuild()
  */
 public function rebuild($position = 0, array &$options = array(), &$detailedMessage = '')
 {
     $options['batch'] = max(1, isset($options['batch']) ? $options['batch'] : 10);
     if ($position == 0) {
         XenForo_Model::create('XenForo_Model_Node')->updateNestedSetInfo();
     }
     /* @var $forumModel XenForo_Model_Forum */
     $forumModel = XenForo_Model::create('XenForo_Model_Forum');
     $forums = $forumModel->getForums(array(), array('limit' => $options['batch'], 'offset' => $position));
     XenForo_Db::beginTransaction();
     foreach ($forums as $forum) {
         $position++;
         $forumDw = XenForo_DataWriter::create('XenForo_DataWriter_Forum', XenForo_DataWriter::ERROR_SILENT);
         if ($forumDw->setExistingData($forum, true)) {
             $forumDw->rebuildCounters();
             $forumDw->save();
         }
     }
     XenForo_Db::commit();
     $detailedMessage = XenForo_Locale::numberFormat($position);
     if (!$forums) {
         return true;
     } else {
         return $position;
     }
 }
Esempio n. 3
0
 public function execute(array $deferred, array $data, $targetRunTime, &$status)
 {
     $data = array_merge(array('position' => 0, 'batch' => 70), $data);
     $data['batch'] = max(1, $data['batch']);
     /* @var $userModel XenForo_Model_User */
     $userModel = XenForo_Model::create('XenForo_Model_User');
     /* @var $conversationModel XenForo_Model_Conversation */
     $conversationModel = XenForo_Model::create('XenForo_Model_Conversation');
     $userIds = $userModel->getUserIdsInRange($data['position'], $data['batch']);
     if (sizeof($userIds) == 0) {
         return true;
     }
     foreach ($userIds as $userId) {
         $data['position'] = $userId;
         /* @var $userDw XenForo_DataWriter_User */
         $userDw = XenForo_DataWriter::create('XenForo_DataWriter_User', XenForo_DataWriter::ERROR_SILENT);
         if ($userDw->setExistingData($userId)) {
             XenForo_Db::beginTransaction();
             $userDw->set('alerts_unread', $userModel->getUnreadAlertsCount($userId));
             $userDw->set('conversations_unread', $conversationModel->countUnreadConversationsForUser($userId));
             $userDw->save();
             $userDw->rebuildUserGroupRelations();
             $userDw->rebuildPermissionCombinationId();
             $userDw->rebuildDisplayStyleGroupId();
             $userDw->rebuildCustomFields();
             $userDw->rebuildIgnoreCache();
             XenForo_Db::commit();
         }
     }
     $actionPhrase = new XenForo_Phrase('rebuilding');
     $typePhrase = new XenForo_Phrase('users');
     $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position']));
     return $data;
 }
Esempio n. 4
0
 /**
  * Rebuilds the data.
  *
  * @see XenForo_CacheRebuilder_Abstract::rebuild()
  */
 public function rebuild($position = 0, array &$options = array(), &$detailedMessage = '')
 {
     $options = array_merge(array('batch' => 100, 'positionRebuild' => false), $options);
     /* @var $threadModel XenForo_Model_Thread */
     $threadModel = XenForo_Model::create('XenForo_Model_Thread');
     $threadIds = $threadModel->getThreadIdsInRange($position, $options['batch']);
     if (sizeof($threadIds) == 0) {
         return true;
     }
     XenForo_Db::beginTransaction();
     foreach ($threadIds as $threadId) {
         $position = $threadId;
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread', XenForo_DataWriter::ERROR_SILENT);
         if ($dw->setExistingData($threadId)) {
             $dw->setOption(XenForo_DataWriter_Discussion::OPTION_UPDATE_CONTAINER, false);
             if ($options['positionRebuild']) {
                 $dw->rebuildDiscussion();
             } else {
                 $dw->rebuildDiscussionCounters();
             }
             $dw->save();
         }
     }
     XenForo_Db::commit();
     $detailedMessage = XenForo_Locale::numberFormat($position);
     return $position;
 }
Esempio n. 5
0
 /**
  * Rebuilds the data.
  *
  * @see XenForo_CacheRebuilder_Abstract::rebuild()
  */
 public function rebuild($position = 0, array &$options = array(), &$detailedMessage = '')
 {
     $options['batch'] = max(1, isset($options['batch']) ? $options['batch'] : 10);
     $socialForumModel = ThemeHouse_SocialGroups_SocialForum::getSocialForumModel();
     if ($position == 0) {
         $socialForumModel->unlinkMovedThreads();
     }
     $socialForums = $socialForumModel->getSocialForums(array(), array('limit' => $options['batch'], 'offset' => $position));
     XenForo_Db::beginTransaction();
     foreach ($socialForums as $socialForum) {
         $position++;
         /* @var $socialForumDw ThemeHouse_SocialGroups_DataWriter_SocialForum */
         $socialForumDw = XenForo_DataWriter::create('ThemeHouse_SocialGroups_DataWriter_SocialForum', XenForo_DataWriter::ERROR_SILENT);
         if ($socialForumDw->setExistingData($socialForum, true)) {
             $socialForumDw->rebuildCounters();
             $socialForumDw->save();
         }
     }
     XenForo_Db::commit();
     $detailedMessage = XenForo_Locale::numberFormat($position);
     if (!$socialForums) {
         return true;
     } else {
         return $position;
     }
 }
 public function execute(array $deferred, array $data, $targetRunTime, &$status)
 {
     return true;
     $data = array_merge(array('position' => 0, 'batch' => 10), $data);
     $data['batch'] = max(1, $data['batch']);
     /* @var $feedbackModel NixFifty_XenTrader_Model_Feedback */
     $feedbackModel = XenForo_Model::create('NixFifty_XenTrader_Model_Feedback');
     $feedbackItems = $feedbackModel->getUserIdsInFeedbackRange($data['position'], $data['batch']);
     if (sizeof($feedbackItems) == 0) {
         return true;
     }
     $db = XenForo_Application::getDb();
     XenForo_Db::beginTransaction($db);
     foreach ($feedbackItems as $feedbackItem) {
         $data['position'] = $item['media_id'];
         $feedbackCount = $db->fetchOne('
             SELECT COUNT(*)
             FROM xf_nixfifty_xentrader_feedback
             WHERE to_user_id = ?
         ', $feedbackItem);
         $db->update('xf_nixfifty_xentrader_user', array('total' => $feedbackCount), 'user_id = ' . $db->quote($feedbackItem));
     }
     XenForo_Db::commit($db);
     $actionPhrase = new XenForo_Phrase('rebuilding');
     $typePhrase = 'fam i think im broken';
     //new XenForo_Phrase('xengallery_rebuild_thumbnails');
     $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position']));
     return $data;
 }
Esempio n. 7
0
 /**
  * Prepares a set of conditions to select fields against.
  *
  * @param array $conditions List of conditions.
  * @param array $fetchOptions The fetch options that have been provided. May be edited if criteria requires.
  *
  * @return string Criteria as SQL for where clause
  */
 public function prepareUserFieldConditions(array $conditions, array &$fetchOptions)
 {
     $db = $this->_getDb();
     $sqlConditions = array();
     if (!empty($conditions['display_group'])) {
         $sqlConditions[] = 'user_field.display_group = ' . $db->quote($conditions['display_group']);
     }
     if (!empty($conditions['profileView'])) {
         $sqlConditions[] = 'user_field.display_group <> \'preferences\' AND user_field.viewable_profile = 1';
     }
     if (!empty($conditions['messageView'])) {
         $sqlConditions[] = 'user_field.display_group <> \'preferences\' AND user_field.viewable_message = 1';
     }
     if (!empty($conditions['registration'])) {
         $sqlConditions[] = 'user_field.required = 1 OR user_field.show_registration = 1';
     }
     if (isset($conditions['moderator_editable'])) {
         $sqlConditions[] = 'user_field.moderator_editable = ' . ($conditions['moderator_editable'] ? 1 : 0);
     }
     if (!empty($conditions['adminQuickSearch'])) {
         $searchStringSql = 'CONVERT(user_field.field_id USING utf8) LIKE ' . XenForo_Db::quoteLike($conditions['adminQuickSearch']['searchText'], 'lr');
         if (!empty($conditions['adminQuickSearch']['phraseMatches'])) {
             $sqlConditions[] = '(' . $searchStringSql . ' OR CONVERT(user_field.field_id USING utf8) IN (' . $db->quote($conditions['adminQuickSearch']['phraseMatches']) . '))';
         } else {
             $sqlConditions[] = $searchStringSql;
         }
     }
     return $this->getConditionsForClause($sqlConditions);
 }
Esempio n. 8
0
 /**
  *
  * @see XenResource_Model_Resource::prepareResourceFetchOptions()
  */
 public function prepareResourceFetchOptions(array $fetchOptions)
 {
     $resourceFetchOptions = parent::prepareResourceFetchOptions($fetchOptions);
     $db = $this->_getDb();
     if (!empty($fetchOptions['order'])) {
         if (strlen($fetchOptions['order']) > strlen('custom_field_') && substr($fetchOptions['order'], 0, strlen('custom_field_')) == 'custom_field_') {
             $customFieldId = substr($fetchOptions['order'], strlen('custom_field_'));
             $fetchOptions['customFields'][$customFieldId] = true;
         }
     }
     if (!empty($fetchOptions['customFields']) && is_array($fetchOptions['customFields'])) {
         foreach ($fetchOptions['customFields'] as $customFieldId => $value) {
             if ($value === '' || is_array($value) && !$value) {
                 continue;
             }
             $isExact = !empty($fetchOptions['customFieldsExact'][$customFieldId]);
             $customFieldId = preg_replace('/[^a-z0-9_]/i', '', $customFieldId);
             $resourceFetchOptions['selectFields'] .= ", resource_field_value_{$customFieldId}.field_value AS custom_field_{$customFieldId}";
             if ($value === true) {
                 $resourceFetchOptions['joinTables'] .= "\n                    LEFT JOIN xf_resource_field_value AS resource_field_value_{$customFieldId} ON\n                    (resource_field_value_{$customFieldId}.resource_id = resource.resource_id\n                    AND resource_field_value_{$customFieldId}.field_id = " . $this->_getDb()->quote($customFieldId) . ")";
             } else {
                 $possibleValues = array();
                 foreach ((array) $value as $possible) {
                     if ($isExact) {
                         $possibleValues[] = "resource_field_value_{$customFieldId}.field_value = " . $this->_getDb()->quote($possible);
                     } else {
                         $possibleValues[] = "resource_field_value_{$customFieldId}.field_value LIKE " . XenForo_Db::quoteLike($possible, 'lr');
                     }
                 }
                 $resourceFetchOptions['joinTables'] .= "\n                    INNER JOIN xf_resource_field_value AS resource_field_value_{$customFieldId} ON\n                    (resource_field_value_{$customFieldId}.resource_id = resource.resource_id\n                    AND resource_field_value_{$customFieldId}.field_id = " . $this->_getDb()->quote($customFieldId) . "\n\t\t\t\t\t\tAND (" . implode(' OR ', $possibleValues) . "))";
             }
         }
     }
     return $resourceFetchOptions;
 }
Esempio n. 9
0
    public function execute(array $deferred, array $data, $targetRunTime, &$status)
    {
        $data = array_merge(array('position' => 0, 'batch' => 10), $data);
        $data['batch'] = max(1, $data['batch']);
        /* @var $albumModel XenGallery_Model_Album */
        $albumModel = XenForo_Model::create('XenGallery_Model_Album');
        $albumIds = $albumModel->getSharedAlbumIdsInRange($data['position'], $data['batch']);
        if (sizeof($albumIds) == 0) {
            return true;
        }
        $db = XenForo_Application::getDb();
        XenForo_Db::beginTransaction($db);
        foreach ($albumIds as $albumId) {
            $data['position'] = $albumId;
            $album = $albumModel->getAlbumByIdSimple($albumId);
            $bind = array($album['album_id'], $album['album_user_id']);
            $ownerShared = $db->fetchOne('SELECT shared_user_id FROM xengallery_shared_map WHERE album_id = ? AND shared_user_id = ?', $bind);
            if (!$ownerShared) {
                $db->query('
					INSERT IGNORE INTO xengallery_shared_map
						(album_id, shared_user_id)
					VALUES
						(?, ?)
				', $bind);
            }
        }
        XenForo_Db::commit($db);
        $actionPhrase = new XenForo_Phrase('rebuilding');
        $typePhrase = new XenForo_Phrase('xengallery_album_permissions');
        $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position']));
        return $data;
    }
Esempio n. 10
0
 public function execute(array $deferred, array $data, $targetRunTime, &$status)
 {
     $data = array_merge(array('position' => 0, 'batch' => 70), $data);
     $data['batch'] = max(1, $data['batch']);
     /* @var $postModel XenForo_Model_Post */
     $postModel = XenForo_Model::create('XenForo_Model_Post');
     $postIds = $postModel->getPostIdsInRange($data['position'], $data['batch']);
     if (sizeof($postIds) == 0) {
         return true;
     }
     foreach ($postIds as $postId) {
         $data['position'] = $postId;
         /* @var $postDw XenForo_DataWriter_DiscussionMessage_Post */
         $postDw = XenForo_DataWriter::create('XenForo_DataWriter_DiscussionMessage_Post', XenForo_DataWriter::ERROR_SILENT);
         if ($postDw->setExistingData($postId)) {
             XenForo_Db::beginTransaction();
             $postDw->rebuildPostVerseCache();
             XenForo_Db::commit();
         }
     }
     $actionPhrase = new XenForo_Phrase('rebuilding');
     $typePhrase = new XenForo_Phrase('posts');
     $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position']));
     return $data;
 }
Esempio n. 11
0
 /**
  * @param int $position
  * @param array $options
  * @param string $detailedMessage
  * @return bool|int|string|true
  */
 public function rebuild($position = 0, array &$options = array(), &$detailedMessage = '')
 {
     $options['batch'] = max(1, isset($options['batch']) ? $options['batch'] : 10);
     /* @var sonnb_XenGallery_Model_Location $locationModel */
     $locationModel = XenForo_Model::create('sonnb_XenGallery_Model_Location');
     $locations = $locationModel->getLocationsWithoutCoordinate($position, $options['batch']);
     if (count($locations) < 1) {
         return true;
     }
     XenForo_Db::beginTransaction();
     $db = XenForo_Application::getDb();
     /** @var sonnb_XenGallery_Model_Location $locationModel */
     $locationModel = XenForo_Model::create('sonnb_XenGallery_Model_Location');
     foreach ($locations as $locationId => $location) {
         $position = $location['location_id'];
         try {
             $client = XenForo_Helper_Http::getClient($locationModel->getGeocodeUrlForAddress($location['location_name']));
             $response = $client->request('GET');
             $response = @json_decode($response->getBody(), true);
             if (empty($response['results'][0])) {
                 continue;
             }
             $address = $response['results'][0]['formatted_address'];
             $lat = $response['results'][0]['geometry']['location']['lat'];
             $lng = $response['results'][0]['geometry']['location']['lng'];
             $db->update('sonnb_xengallery_location', array('location_name' => $address, 'location_lat' => $lat, 'location_lng' => $lng), array('location_id = ?' => $location['location_id']));
         } catch (Exception $e) {
             continue;
         }
     }
     XenForo_Db::commit();
     $detailedMessage = XenForo_Locale::numberFormat($position);
     return $position;
 }
Esempio n. 12
0
 /**
  * Rebuilds the data.
  *
  * @see XenForo_CacheRebuilder_Abstract::rebuild()
  */
 public function rebuild($position = 0, array &$options = array(), &$detailedMessage = '')
 {
     $options['batch'] = isset($options['batch']) ? $options['batch'] : 75;
     $options['batch'] = max(1, $options['batch']);
     /* @var $userModel XenForo_Model_User */
     $userModel = XenForo_Model::create('XenForo_Model_User');
     /* @var $conversationModel XenForo_Model_Conversation */
     $conversationModel = XenForo_Model::create('XenForo_Model_Conversation');
     $userIds = $userModel->getUserIdsInRange($position, $options['batch']);
     if (sizeof($userIds) == 0) {
         return true;
     }
     XenForo_Db::beginTransaction();
     foreach ($userIds as $userId) {
         $position = $userId;
         /* @var $userDw XenForo_DataWriter_User */
         $userDw = XenForo_DataWriter::create('XenForo_DataWriter_User', XenForo_DataWriter::ERROR_SILENT);
         if ($userDw->setExistingData($userId)) {
             $userDw->set('alerts_unread', $userModel->getUnreadAlertsCount($userId));
             $userDw->set('conversations_unread', $conversationModel->countUnreadConversationsForUser($userId));
             $userDw->save();
             $userDw->rebuildUserGroupRelations();
             $userDw->rebuildPermissionCombinationId();
             $userDw->rebuildDisplayStyleGroupId();
             $userDw->rebuildIdentities();
         }
     }
     XenForo_Db::commit();
     $detailedMessage = XenForo_Locale::numberFormat($position);
     return $position;
 }
Esempio n. 13
0
 /**
  * @see XenForo_CacheRebuilder_DailyStats::rebuild()
  */
 public function rebuild($position = 0, array &$options = array(), &$detailedMessage = '')
 {
     $options['batch'] = isset($options['batch']) ? $options['batch'] : 28;
     $options['batch'] = max(1, $options['batch']);
     /* @var $userModel XenForo_Model_Stats */
     $statsModel = XenForo_Model::create('XenForo_Model_Stats');
     if ($position == 0) {
         // delete old stats cache if required
         if (!empty($options['delete'])) {
             $statsModel->deleteStats();
         }
         $xenOptions = XenForo_Application::get('options');
         // an appropriate date from which to start... first thread, or earliest user reg?
         if ($xenOptions->th_noForo_noForum) {
             $position = XenForo_Model::create('XenForo_Model_User')->getEarliestRegistrationDate();
         } else {
             $position = min(XenForo_Model::create('XenForo_Model_Thread')->getEarliestThreadDate(), XenForo_Model::create('XenForo_Model_User')->getEarliestRegistrationDate());
         }
         // start on a 24 hour increment point
         $position = $position - $position % 86400;
     } else {
         if ($position > XenForo_Application::$time) {
             return true;
         }
     }
     XenForo_Db::beginTransaction();
     $endPosition = $position + $options['batch'] * 86400;
     $data = $statsModel->buildStatsData($position, $endPosition);
     XenForo_Db::commit();
     $detailedMessage = XenForo_Locale::date($position, 'absolute');
     return $endPosition;
 }
Esempio n. 14
0
 public function execute(array $deferred, array $data, $targetRunTime, &$status)
 {
     $data = array_merge(array('tagId' => null, 'position' => 0, 'deleteFirst' => false), $data);
     if (!$data['tagId']) {
         return false;
     }
     $db = XenForo_Application::getDb();
     $matches = $db->fetchAll("\r\n\t\t\tSELECT tag_content_id, content_type, content_id\r\n\t\t\tFROM xf_tag_content\r\n\t\t\tWHERE tag_id = ?\r\n\t\t\t\tAND tag_content_id > ?\r\n\t\t\tORDER BY tag_content_id\r\n\t\t\tLIMIT 1000\r\n\t\t", array($data['tagId'], $data['position']));
     if (!$matches) {
         return false;
     }
     /** @var XenForo_Model_Tag $tagModel */
     $tagModel = XenForo_Model::create('XenForo_Model_Tag');
     XenForo_Db::beginTransaction($db);
     $limitTime = $targetRunTime > 0;
     $s = microtime(true);
     foreach ($matches as $match) {
         $data['position'] = $match['tag_content_id'];
         if ($data['deleteFirst']) {
             $db->delete('xf_tag_content', 'tag_content_id = ' . $match['tag_content_id']);
         }
         $tagModel->rebuildTagCache($match['content_type'], $match['content_id']);
         if ($limitTime && microtime(true) - $s >= $targetRunTime) {
             break;
         }
     }
     XenForo_Db::commit($db);
     $actionPhrase = new XenForo_Phrase('rebuilding');
     $typePhrase = new XenForo_Phrase('tags');
     $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position']));
     return $data;
 }
Esempio n. 15
0
 public static function uninstall()
 {
     //Get the db
     $db = XenForo_Application::getDb();
     XenForo_Db::beginTransaction($db);
     //Drop the custom tables from the db
     try {
         $db->query("\n\t\t\t    DROP TABLE IF EXISTS `xf_thread_rating`\n\t\t   ");
     } catch (Zend_Db_Exception $e) {
     }
     //Drop the `rating_count` field from the thread table
     try {
         $db->query("\n\t\t\t\tALTER TABLE xf_thread\n\t\t\t\t\tDROP COLUMN `rating_count`\n\t\t\t");
     } catch (Zend_Db_Exception $e) {
     }
     //Drop the `rating_sum` field from the thread table
     try {
         $db->query("\n\t\t\t\tALTER TABLE xf_thread\n\t\t\t\t\tDROP COLUMN `rating_sum`\n\t\t\t");
     } catch (Zend_Db_Exception $e) {
     }
     //Drop the `rating_avg` field from the thread table
     try {
         $db->query("\n\t\t\t\tALTER TABLE xf_thread\n\t\t\t\t\tDROP COLUMN `rating_avg`\n\t\t\t");
     } catch (Zend_Db_Exception $e) {
     }
     XenForo_Db::commit($db);
 }
 /**
  * Gives a user the specified promotion.
  *
  * @param array $promotion
  * @param integer $userId
  * @param string $state Type of promotion (automatic, manual); this affects
  * automatic demotion
  * @param integer $endDate
  */
 public function promoteUserWithEndDate(array $promotion, $userId, $state = 'automatic', $endDate)
 {
     $db = $this->_getDb();
     XenForo_Db::beginTransaction($db);
     $this->_getUserModel()->addUserGroupChange($userId, "ugPromotion{$promotion['promotion_id']}", $promotion['extra_user_group_ids']);
     $this->insertPromotionLogEntryWithEndDate($promotion['promotion_id'], $userId, $state, $endDate);
     XenForo_Db::commit($db);
 }
Esempio n. 17
0
 public static function uninstaller()
 {
     $db = self::_getDb();
     XenForo_Db::beginTransaction($db);
     if (self::_doesIndexExist()) {
         self::_dropIndex();
     }
     XenForo_Db::commit($db);
 }
 public function run($addonId, $path)
 {
     $addonModel = XenForo_Model::create('XenForo_Model_AddOn');
     $this->printMessage('Importing ' . $addonId . ' from ' . realPath($path) . '...');
     $print = 'importing addon.xml...';
     $print .= str_repeat(' ', $this->_column - strlen($print));
     $t = microtime(true);
     $m = memory_get_usage(true);
     $this->printMessage($print, false);
     $xml = new SimpleXMLElement($path . '/addon.xml', 0, true);
     $addOnData = array('addon_id' => (string) $xml['addon_id'], 'title' => (string) $xml['title'], 'version_string' => (string) $xml['version_string'], 'version_id' => (string) $xml['version_id'], 'install_callback_class' => (string) $xml['install_callback_class'], 'install_callback_method' => (string) $xml['install_callback_method'], 'uninstall_callback_class' => (string) $xml['uninstall_callback_class'], 'uninstall_callback_method' => (string) $xml['uninstall_callback_method'], 'url' => (string) $xml['url']);
     $version = file_get_contents($path . '/version.txt');
     if ($version) {
         foreach ($addOnData as &$data) {
             $data = str_replace('{@revision}', $version, $data);
         }
     }
     $addOnData['version_id'] = (int) $addOnData['version_id'];
     $existingAddOn = $addonModel->verifyAddOnIsInstallable($addOnData, $addonModel->getAddonById($addonId) ? $addonId : false);
     $db = XenForo_Application::getDb();
     XenForo_Db::beginTransaction($db);
     if ($addOnData['install_callback_class'] && $addOnData['install_callback_method']) {
         call_user_func(array($addOnData['install_callback_class'], $addOnData['install_callback_method']), $existingAddOn, $addOnData);
     }
     $addOnDw = XenForo_DataWriter::create('XenForo_DataWriter_AddOn');
     if ($existingAddOn) {
         $addOnDw->setExistingData($existingAddOn, true);
     }
     $addOnDw->bulkSet($addOnData);
     $addOnDw->save();
     $t = abs(microtime(true) - $t);
     $m = abs(memory_get_usage(true) - $m);
     $m = $m / 1024 / 1024;
     $this->printMessage('done (' . number_format($t, 2) . 'sec, ' . number_format($m, 2) . 'mb)');
     $this->_importXml($addonId, $path . '/admin_navigation.xml', 'AdminNavigation');
     $this->_importXml($addonId, $path . '/admin_permissions.xml', 'Admin', 'importAdminPermissionsAddOnXml');
     $this->_importXml($addonId, $path . '/code_events.xml', 'CodeEvent', 'importEventsAddOnXml');
     $this->_importXml($addonId, $path . '/code_event_listeners.xml', 'CodeEvent', 'importEventListenersAddOnXml');
     $this->_importXml($addonId, $path . '/cron.xml', 'Cron', 'importCronEntriesAddOnXml');
     $this->_importXml($addonId, $path . '/email_templates.xml', 'EmailTemplate');
     $this->_importXml($addonId, $path . '/options.xml', 'Option');
     $this->_importXml($addonId, $path . '/permissions.xml', 'Permission');
     $this->_importXml($addonId, $path . '/route_prefixes.xml', 'RoutePrefix', 'importPrefixesAddOnXml');
     $this->_importXml($addonId, $path . '/style_properties.xml', 'StyleProperty', 'importStylePropertyXml', array(0, $addonId));
     $this->_importXml($addonId, $path . '/admin_style_properties.xml', 'StyleProperty', 'importStylePropertyXml', array(-1, $addonId));
     foreach (array('templates/admin', 'templates/master', 'phrases') as $dir) {
         $this->_removeDirectory(XenForo_Application::getInstance()->getRootDir() . '/' . $dir . '/' . $addonId);
     }
     $this->_importXml($addonId, $path . '/templates.xml', 'Template');
     $this->_importXml($addonId, $path . '/admin_templates.xml', 'AdminTemplate');
     $this->_importXml($addonId, $path . '/phrases.xml', 'Phrase');
     // TODO: bbcode
     XenForo_Db::commit($db);
     $this->printEmptyLine();
     $this->manualRun('rebuild', false, false, array('caches' => 'addon'));
 }
Esempio n. 19
0
 public function resetLayout($layout)
 {
     $db = $this->_getDb();
     XenForo_Db::beginTransaction($db);
     $dw = XenForo_DataWriter::create('EWRporta_DataWriter_Layouts');
     $dw->setExistingData($layout);
     $dw->delete();
     XenForo_Db::commit($db);
     return true;
 }
Esempio n. 20
0
 public static function verifyPosition(&$positions, XenForo_DataWriter $dw, $fieldName = false)
 {
     $positions = trim($positions);
     if (empty($positions)) {
         $dw->error(new XenForo_Phrase('wf_position_can_not_be_empty'), $fieldName);
     }
     if ('all' == $positions) {
         return true;
     }
     /** @var XenForo_Model_Template $templateModel */
     $templateModel = $dw->getModelFromCache('XenForo_Model_Template');
     $db = XenForo_Application::getDb();
     $positionsArray = explode(',', $positions);
     $positionsGood = array();
     $templateForHooks = array();
     foreach ($positionsArray as $position) {
         $position = trim($position);
         if (empty($position)) {
             continue;
         }
         if (in_array($position, array('wf_widget_page', 'hook:wf_widget_page_contents'), true) and !$dw->get('widget_page_id')) {
             $dw->error(new XenForo_Phrase('wf_position_x_requires_widget_page', array('position' => $position)), $fieldName);
             return false;
         }
         if (in_array($position, array('wf_widget_ajax'), true)) {
             $dw->error(new XenForo_Phrase('wf_invalid_position_x', array('position' => $position)), $fieldName);
             return false;
         }
         // sondh@2012-08-25
         // added support for hook:hook_name
         if (substr($position, 0, 5) == 'hook:') {
             // accept all kind of hooks, just need to get parent templates for them
             $templates = $db->fetchAll("\n\t\t\t\t\tSELECT title\n\t\t\t\t\tFROM `xf_template_compiled`\n\t\t\t\t\tWHERE template_compiled LIKE " . XenForo_Db::quoteLike('callTemplateHook(\'' . substr($position, 5) . '\',', 'lr') . "\n\t\t\t\t");
             if (count($templates) > 0) {
                 $templateForHooks[$position] = array();
                 foreach ($templates as $template) {
                     $templateForHooks[$position][] = $template['title'];
                 }
                 $templateForHooks[$position] = array_unique($templateForHooks[$position]);
             } else {
                 $dw->error(new XenForo_Phrase('wf_non_existent_hook_x', array('hook' => substr($position, 5))), $fieldName);
                 return false;
             }
         } elseif (!$templateModel->getTemplateInStyleByTitle($position)) {
             $dw->error(new XenForo_Phrase('wf_invalid_position_x', array('position' => $position)), $fieldName);
             return false;
         }
         $positionsGood[] = $position;
     }
     $dw->setExtraData(WidgetFramework_DataWriter_Widget::EXTRA_DATA_TEMPLATE_FOR_HOOKS, $templateForHooks);
     asort($positionsGood);
     $positions = implode(', ', $positionsGood);
     return true;
 }
 public function rebuildUnreadConversationCountForUser($userId)
 {
     if (SV_DeadlockAvoidance_DataWriter::registerPostTransactionClosure(function () use($userId) {
         XenForo_Db::beginTransaction();
         parent::rebuildUnreadConversationCountForUser($userId);
         XenForo_Db::commit();
     })) {
         return;
     }
     parent::rebuildUnreadConversationCountForUser($userId);
 }
Esempio n. 22
0
 public function deleteUserRecords($userId)
 {
     $records = $this->getPurchases(array('user_id' => $userId));
     XenForo_Db::beginTransaction();
     foreach ($records as $record) {
         $dw = XenForo_DataWriter::create('bdPaygate_DataWriter_Purchase');
         $dw->setExistingData($record, true);
         $dw->delete();
     }
     XenForo_Db::commit();
     return count($records);
 }
Esempio n. 23
0
 public function recountRatings()
 {
     @set_time_limit(0);
     ignore_user_abort(true);
     XenForo_Application::getDb()->setProfiler(false);
     $db = $this->_getDb();
     //Delete ratings(s) given in threads that do not exists anymore
     $db->query("DELETE ratings.*\n \t\t            FROM xf_thread_rating AS ratings\n\t\t\t\t\tLEFT JOIN xf_thread AS thread \n\t\t\t\t\tON (ratings.thread_id = thread.thread_id)\n\t\t\t\t\tWHERE thread.thread_id IS NULL\n\t\t");
     //Delete ratings(s) given by users that do not exists anymore
     $db->query("DELETE ratings.* \n\t\t            FROM xf_thread_rating AS ratings\n\t\t\t\t\tLEFT JOIN xf_user AS user \n\t\t\t\t\tON (ratings.user_id = user.user_id)\n\t\t\t\t\tWHERE user.user_id IS NULL\n\t\t");
     XenForo_Db::commit($db);
 }
Esempio n. 24
0
    public function stepFriends($start, array $options)
    {
        $options = array_merge(array('limit' => 100, 'max' => false), $options);
        $sDb = $this->_sourceDb;
        $prefix = $this->_prefix;
        /* @var $model XenForo_Model_Import */
        $model = $this->_importModel;
        if ($options['max'] === false) {
            $options['max'] = $sDb->fetchOne('
				SELECT MAX(userid)
				FROM ' . $prefix . 'userlist
			');
        }
        $friends = $sDb->fetchAll($sDb->limit('
				SELECT *
				FROM ' . $prefix . 'userlist AS userlist
				WHERE userlist.userid > ' . $sDb->quote($start) . '
                    AND userlist.type = \'buddy\' AND userlist.friend IN (\'yes\', \'pending\')
				ORDER BY userlist.userid
			', $options['limit']));
        if (!$friends) {
            return true;
        }
        $next = 0;
        $total = 0;
        XenForo_Db::beginTransaction();
        foreach ($friends as $friend) {
            $next = $friend['userid'];
            $userId = $model->mapUserId($friend['userid'], 0);
            $friendUserId = $model->mapUserId($friend['relationid'], 0);
            if (!$userId || !$friendUserId) {
                continue;
            }
            /* @var $userModel XenForo_Model_User */
            $userModel = XenForo_Model::create('XenForo_Model_User');
            $friendRecord = $userModel->getFriendRecord($userId, $friendUserId);
            $dw = XenForo_DataWriter::create('ThemeHouse_Friends_DataWriter_Friend');
            if ($friendRecord) {
                $dw->setExistingData($friendRecord);
            } else {
                $dw->set('user_id', $userId);
                $dw->set('friend_user_id', $friendUserId);
                $dw->set('message', 'n/a');
            }
            $dw->set('friend_state', $friend['friend'] == 'pending' ? 'pending' : 'confirmed');
            $dw->save();
            $total++;
        }
        XenForo_Db::commit();
        $this->_session->incrementStepImportTotal($total);
        return array($next, $options, $this->_getProgressOutput($next, $options['max']));
    }
Esempio n. 25
0
 public function prepareTermConditions(array $conditions, array &$fetchOptions)
 {
     $db = $this->_getDb();
     $sqlConditions = array();
     if (!empty($conditions['value'])) {
         if (is_array($conditions['value'])) {
             $sqlConditions[] = 'terms.value LIKE ' . XenForo_Db::quoteLike($conditions['value'][0], $conditions['value'][1], $db);
         } else {
             $sqlConditions[] = 'terms.value LIKE ' . XenForo_Db::quoteLike($conditions['value'], 'lr', $db);
         }
     }
     return $this->getConditionsForClause($sqlConditions);
 }
Esempio n. 26
0
 /**
  * Prepares a collection of link proxy fetching related conditions into an SQL clause
  *
  * @param array $conditions List of conditions
  * @param array $fetchOptions Modifiable set of fetch options (may have joins pushed on to it)
  *
  * @return string SQL clause (at least 1=1)
  */
 public function prepareLinkProxyConditions(array $conditions, array &$fetchOptions)
 {
     $sqlConditions = array();
     $db = $this->_getDb();
     if (!empty($conditions['url'])) {
         if (is_array($conditions['url'])) {
             $sqlConditions[] = 'link_proxy.url LIKE ' . XenForo_Db::quoteLike($conditions['url'][0], $conditions['url'][1], $db);
         } else {
             $sqlConditions[] = 'link_proxy.url LIKE ' . XenForo_Db::quoteLike($conditions['url'], 'lr', $db);
         }
     }
     return $this->getConditionsForClause($sqlConditions);
 }
Esempio n. 27
0
 /**
  * Updates the given set of user titles. The set is assumed to be all user titles,
  * as the existing ones are removed before updating.
  *
  * @param array $titles [] => [title, minimum_level]
  * @param boolean $rebuildCache If true, rebuilds the user title cache
  */
 public function updateUserTitleLadder(array $titles, $rebuildCache = true)
 {
     $db = $this->_getDb();
     XenForo_Db::beginTransaction($db);
     $db->delete('xf_user_title_ladder');
     foreach ($titles as $titleInfo) {
         if (isset($titleInfo['title'], $titleInfo['minimum_level'])) {
             $this->insertUserTitleLadderEntry($titleInfo['title'], $titleInfo['minimum_level'], false);
         }
     }
     if ($rebuildCache) {
         $this->rebuildUserTitleLadderCache();
     }
     XenForo_Db::commit($db);
 }
Esempio n. 28
0
 public function actionDelete()
 {
     $id = $this->_input->filterSingle('tag_id', XenForo_Input::UINT);
     $tag = $this->_getTagOrError($id);
     if ($this->isConfirmedPost()) {
         XenForo_Db::beginTransaction();
         $dw = $this->_getTagDataWriter();
         $dw->setExistingData($id);
         $dw->delete();
         XenForo_Db::commit();
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildAdminLink('xentag-tags'));
     } else {
         $viewParams = array('tag' => $tag);
         return $this->responseView('Tinhte_XenTag_ViewAdmin_Tag_Delete', 'tinhte_xentag_tag_delete', $viewParams);
     }
 }
Esempio n. 29
0
 public function importListenersXml(SimpleXMLElement $xml, $blockId)
 {
     $db = $this->_getDb();
     XenForo_Db::beginTransaction($db);
     $this->deleteListenersByBlock($blockId);
     $listeners = XenForo_Helper_DevelopmentXml::fixPhpBug50670($xml->listener);
     foreach ($listeners as $event) {
         $eventId = (string) $event['event_id'];
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_CodeEventListener');
         $dw->setOption(XenForo_DataWriter_CodeEventListener::OPTION_REBUILD_CACHE, false);
         $dw->bulkSet(array('event_id' => (string) $event['event_id'], 'execute_order' => (string) $event['execute_order'], 'callback_class' => (string) $event['callback_class'], 'callback_method' => (string) $event['callback_method'], 'active' => (string) $event['active'], 'description' => (string) $event['description']));
         $dw->save();
     }
     $this->getModelFromCache('XenForo_Model_CodeEvent')->rebuildEventListenerCache();
     XenForo_Db::commit($db);
     return;
 }
Esempio n. 30
0
 public function importAdminTemplatesXml(SimpleXMLElement $xml, $blockId)
 {
     $existingAdminTemplates = $this->getAdminTemplatesByBlock($blockId);
     $db = $this->_getDb();
     XenForo_Db::beginTransaction($db);
     foreach ($xml->template as $template) {
         $templateName = (string) $template['title'];
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_AdminTemplate');
         if (isset($existingAdminTemplates[$templateName])) {
             $dw->setExistingData($existingAdminTemplates[$templateName], true);
         }
         $dw->bulkSet(array('title' => $templateName, 'template' => XenForo_Helper_DevelopmentXml::processSimpleXmlCdata($template)));
         $dw->save();
     }
     XenForo_Db::commit($db);
     return;
 }