/** * creates an image record for each image which was selected in the select-box */ private function createRecords() { $url = $this->feedImport['feed_url']; // TODO: import image from media feed //$fileNames = explode(',', ); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 0); $data = curl_exec($ch); curl_close($ch); $xml = new SimpleXMLElement($data, LIBXML_NOCDATA); $maxImages = 5; foreach ($xml->channel[0]->item as $item) { $mediaProperties = $item->children('http://search.yahoo.com/mrss/'); $mediaContent = $mediaProperties->content[0]; $imageUrl = $mediaContent->attributes()->url; $fileName = $this->getFilenameFromUrl($imageUrl); if (trim($fileName) && !isset($this->images[$fileName])) { $filepath = PATH_site . 'uploads/tx_gorillary/' . $fileName; $this->downloadFile($imageUrl, $filepath); $newRecord = array('pid' => $this->feedImport['pid'], 'feedimport' => $this->feedImport['uid'], 'crdate' => time(), 'cruser_id' => $this->feedImport['cruser_id'], 'image' => $fileName, 'title' => trim($item->title), 'description' => trim($item->description), 'link' => $item->link); $this->db->exec_INSERTquery('tx_gorillary_images', $newRecord); $newRecord['uid'] = $this->db->sql_insert_id(); $this->images[$fileName] = $newRecord; } $maxImages--; if ($maxImages == 0) { break; } } }
/** * @test */ public function storedGzipCompressedDataReturnsSameData() { $testStringWithBinary = @gzcompress('sdfkljer4587'); $this->fixture->exec_INSERTquery($this->testTable, array('fieldblob' => $testStringWithBinary)); $id = $this->fixture->sql_insert_id(); $entry = $this->fixture->exec_SELECTgetRows('fieldblob', $this->testTable, 'id = ' . $id); $this->assertEquals($testStringWithBinary, $entry[0]['fieldblob']); }
/** * creates an image record for each image which was selected in the select-box */ private function createRecords() { $fileNames = explode(',', $this->collection['images']); foreach ($fileNames as $fileName) { if (trim($fileName) && !isset($this->images[$fileName])) { $newRecord = array('pid' => $this->collection['pid'], 'collection' => $this->collection['uid'], 'crdate' => time(), 'cruser_id' => $this->collection['cruser_id'], 'image' => $fileName, 'title' => $this->getTitleFromName($fileName)); $this->db->exec_INSERTquery('tx_gorillary_images', $newRecord); $newRecord['uid'] = $this->db->sql_insert_id(); $this->images[$fileName] = $newRecord; } } }
/** * Process not yet migrated tx_news category records to sys_category records */ protected function migrateNewsCategoryRecords() { $rows = $this->databaseConnection->exec_SELECTgetRows('uid, pid, tstamp, crdate, cruser_id, starttime, endtime, sorting, ' . 'sys_language_uid, l10n_parent, l10n_diffsource, ' . 'title, description, ' . 'fe_group, single_pid, shortcut, import_id, import_source', 'tx_news_domain_model_category', 'migrate_sys_category_uid = 0 AND deleted = 0'); if ($this->databaseConnection->sql_error()) { $message = ' SQL ERROR: ' . $this->databaseConnection->sql_error(); $status = FlashMessage::ERROR; $title = 'Failed selecting old category records'; $this->messageArray[] = array($status, $title, $message); } // Create a new sys_category record for each found record $newCategoryRecords = 0; foreach ($rows as $row) { $oldUid = $row['uid']; unset($row['uid']); if (is_null($row['l10n_diffsource'])) { $row['l10n_diffsource'] = ''; } if ($this->databaseConnection->exec_INSERTquery('sys_category', $row) !== FALSE) { $newUid = $this->databaseConnection->sql_insert_id(); $this->databaseConnection->exec_UPDATEquery('tx_news_domain_model_category', 'uid=' . $oldUid, array('migrate_sys_category_uid' => $newUid)); $newCategoryRecords++; } else { $message = ' SQL ERROR: ' . $this->databaseConnection->sql_error(); $status = FlashMessage::ERROR; $title = 'Failed copying [' . $oldUid . '] ' . htmlspecialchars($row['title']) . ' to sys_category'; $this->messageArray[] = array($status, $title, $message); } } $message = 'Created ' . $newCategoryRecords . ' sys_category records'; $status = FlashMessage::INFO; $title = ''; $this->messageArray[] = array($status, $title, $message); }
/** * Sets the entry to cache. * * @param UrlCacheEntry $cacheEntry * @return void */ public function putUrlToCache(UrlCacheEntry $cacheEntry) { $data = array('original_url' => $cacheEntry->getOriginalUrl(), 'page_id' => $cacheEntry->getPageId(), 'request_variables' => json_encode($cacheEntry->getRequestVariables()), 'rootpage_id' => $cacheEntry->getRootPageId(), 'speaking_url' => $cacheEntry->getSpeakingUrl()); if ($cacheEntry->getCacheId()) { $this->databaseConnection->exec_UPDATEquery('tx_realurl_urlcache', 'uid=' . $this->databaseConnection->fullQuoteStr($cacheEntry->getCacheId(), 'tx_realurl_urlcache'), $data); } else { $this->databaseConnection->exec_INSERTquery('tx_realurl_urlcache', $data); $cacheEntry->setCacheId($this->databaseConnection->sql_insert_id()); } }
/** * Add is_dummy_record record and create dummy record * * @return void */ private function prepareTables() { $sql = 'ALTER TABLE %s ADD is_dummy_record tinyint(1) unsigned DEFAULT \'0\' NOT NULL'; foreach ($this->tables as $table) { $_sql = sprintf($sql, $table); $this->database->sql_query($_sql); } $values = array('title' => $this->getUniqueId('title'), 'l10n_diffsource' => '', 'description' => '', 'is_dummy_record' => 1); $this->database->exec_INSERTquery('sys_category', $values); $this->categoryUid = $this->database->sql_insert_id(); }
/** * Read URL for not-yet-inserted log-entry * * @param integer Queue field array, * @return string */ function readUrlFromArray($field_array) { // Set exec_time to lock record: $field_array['exec_time'] = $this->getCurrentTime(); $this->db->exec_INSERTquery('tx_crawler_queue', $field_array); $queueId = $field_array['qid'] = $this->db->sql_insert_id(); $result = $this->readUrl_exec($field_array); // Set result in log which also denotes the end of the processing of this entry. $field_array = array('result_data' => serialize($result)); $this->db->exec_UPDATEquery('tx_crawler_queue', 'qid=' . intval($queueId), $field_array); return $result; }
/** * Create the initial local storage base e.g. for the fileadmin/ directory. * * @param string $name * @param string $basePath * @param string $pathType * @param string $description * @param bool $default set to default storage * @return int uid of the inserted record */ public function createLocalStorage($name, $basePath, $pathType, $description = '', $default = false) { $caseSensitive = $this->testCaseSensitivity($pathType === 'relative' ? PATH_site . $basePath : $basePath); // create the FlexForm for the driver configuration $flexFormData = array('data' => array('sDEF' => array('lDEF' => array('basePath' => array('vDEF' => rtrim($basePath, '/') . '/'), 'pathType' => array('vDEF' => $pathType), 'caseSensitive' => array('vDEF' => $caseSensitive))))); /** @var $flexObj FlexFormTools */ $flexObj = GeneralUtility::makeInstance(FlexFormTools::class); $flexFormXml = $flexObj->flexArray2Xml($flexFormData, true); // create the record $field_values = array('pid' => 0, 'tstamp' => $GLOBALS['EXEC_TIME'], 'crdate' => $GLOBALS['EXEC_TIME'], 'name' => $name, 'description' => $description, 'driver' => 'Local', 'configuration' => $flexFormXml, 'is_online' => 1, 'is_browsable' => 1, 'is_public' => 1, 'is_writable' => 1, 'is_default' => $default ? 1 : 0); $this->db->exec_INSERTquery('sys_file_storage', $field_values); return (int) $this->db->sql_insert_id(); }
/** * Adds a row to the storage * * @param string $tableName The database table name * @param array $fieldValues The row to be inserted * @param bool $isRelation TRUE if we are currently inserting into a relation table, FALSE by default * @return int The uid of the inserted row */ public function addRow($tableName, array $fieldValues, $isRelation = FALSE) { if (isset($fieldValues['uid'])) { unset($fieldValues['uid']); } $this->databaseHandle->exec_INSERTquery($tableName, $fieldValues); $this->checkSqlErrors(); $uid = $this->databaseHandle->sql_insert_id(); if (!$isRelation) { $this->clearPageCache($tableName, $uid); } return (int) $uid; }
/** * Adds a processedfile object in the database * * @param ProcessedFile $processedFile * @return void */ public function add($processedFile) { if ($processedFile->isPersisted()) { $this->update($processedFile); } else { $insertFields = $processedFile->toArray(); $insertFields['crdate'] = $insertFields['tstamp'] = time(); $insertFields = $this->cleanUnavailableColumns($insertFields); $this->databaseConnection->exec_INSERTquery($this->table, $insertFields); $uid = $this->databaseConnection->sql_insert_id(); $processedFile->updateProperties(array('uid' => $uid)); } }
/** * Migrate locations with relations * * @return void */ protected function migrateLocations() { $locations = $this->fetchLocations(); while ($row = $this->database->sql_fetch_assoc($locations)) { $location = $this->mapFieldsPreImport($row, 'locations'); $table = 'tx_storefinder_domain_model_location'; if ($record = $this->isAlreadyImported($location, $table)) { unset($location['import_id']); $this->database->exec_UPDATEquery($table, 'uid = ' . $record['uid'], $location); $this->records['locations'][$row['uid']] = $location['uid'] = $record['uid']; } else { $this->database->exec_INSERTquery($table, $location); $this->records['locations'][$row['uid']] = $location['uid'] = $this->database->sql_insert_id(); } $this->mapFieldsPostImport($row, $location, 'locations'); $this->migrateFilesToFal($row, $location, $this->fileMapping['locations']['media']); $this->migrateFilesToFal($row, $location, $this->fileMapping['locations']['imageurl']); $this->migrateFilesToFal($row, $location, $this->fileMapping['locations']['icon']); } $this->database->sql_query(' update tx_storefinder_domain_model_location AS l LEFT JOIN ( SELECT uid_foreign, COUNT(*) AS count FROM sys_category_record_mm WHERE tablenames = \'tx_storefinder_domain_model_location\' AND fieldname = \'categories\' GROUP BY uid_foreign ) AS c ON l.uid = c.uid_foreign set l.categories = COALESCE(c.count, 0); '); $this->database->sql_query(' update tx_storefinder_domain_model_location AS l LEFT JOIN ( SELECT uid_local, COUNT(*) AS count FROM tx_storefinder_location_attribute_mm GROUP BY uid_local ) AS a ON l.uid = a.uid_local set l.attributes = COALESCE(a.count, 0); '); $this->database->sql_query(' update tx_storefinder_domain_model_location AS l LEFT JOIN ( SELECT uid_local, COUNT(*) AS count FROM tx_storefinder_location_location_mm GROUP BY uid_local ) AS a ON l.uid = a.uid_local set l.related = COALESCE(a.count, 0); '); $this->messageArray[] = array('message' => count($this->records['locations']) . ' locations migrated'); }
/** * Log the access of the file * * @param integer|null $intFileSize */ protected function logDownload($intFileSize = null) { if ($this->isLoggingEnabled()) { if (is_null($intFileSize)) { $intFileSize = $this->fileSize; } $data_array = array('tstamp' => time(), 'file_name' => $this->file, 'file_size' => $intFileSize, 'user_id' => intval($this->feUserObj->user['uid'])); if (is_null($this->logRowUid)) { $this->databaseConnection->exec_INSERTquery('tx_nawsecuredl_counter', $data_array); $this->logRowUid = $this->databaseConnection->sql_insert_id(); } else { $this->databaseConnection->exec_UPDATEquery('tx_nawsecuredl_counter', '`uid`=' . (int) $this->logRowUid, $data_array); } } }
/** * Sets the entry to cache. * * @param UrlCacheEntry $cacheEntry * @return void */ public function putUrlToCache(UrlCacheEntry $cacheEntry) { $data = array('expire' => $cacheEntry->getExpiration(), 'original_url' => $cacheEntry->getOriginalUrl(), 'page_id' => $cacheEntry->getPageId(), 'request_variables' => json_encode($cacheEntry->getRequestVariables()), 'rootpage_id' => $cacheEntry->getRootPageId(), 'speaking_url' => $cacheEntry->getSpeakingUrl()); if ($cacheEntry->getCacheId()) { $this->databaseConnection->exec_UPDATEquery('tx_realurl_urldata', 'uid=' . $this->databaseConnection->fullQuoteStr($cacheEntry->getCacheId(), 'tx_realurl_urldata'), $data); } else { $this->databaseConnection->sql_query('START TRANSACTION'); if ($this->limitTableRecords('tx_realurl_urldata')) { $this->databaseConnection->sql_query('DELETE FROM tx_realurl_uniqalias_cache_map WHERE url_cache_id NOT IN (SELECT uid FROM tx_realurl_urldata)'); } $this->databaseConnection->exec_INSERTquery('tx_realurl_urldata', $data); $cacheEntry->setCacheId($this->databaseConnection->sql_insert_id()); $this->databaseConnection->sql_query('COMMIT'); } }
/** * Writes changes into database * * @return void */ public function updateDatabase() { if (!is_array($this->data)) { return; } $diff = array_diff_assoc($this->data, $this->origData); foreach ($diff as $key => $value) { if (!isset($this->data[$key])) { unset($diff[$key]); } } if (!empty($diff)) { $this->data['tstamp'] = $diff['tstamp'] = $GLOBALS['EXEC_TIME']; if (intVal($this->data['uid']) > 0) { $this->databaseHandle->exec_UPDATEquery($this->getTableName(), 'uid=' . $this->getUid(), $diff); } else { $this->data['crdate'] = $diff['crdate'] = $GLOBALS['EXEC_TIME']; $this->databaseHandle->exec_INSERTquery($this->getTableName(), $diff); $this->setUid($this->databaseHandle->sql_insert_id()); $this->data['uid'] = $this->getUid(); } $this->origData = $this->data; } }
/** * Creates a frontend user based on the data of the social user * * @param array $user * @param string $provider * @param string $identifier * * @return array|FALSE the created identity record or false if it is not possible */ protected function addIdentityToFrontendUser($user, $provider, $identifier) { $result = false; $identityClassName = 'Portrino\\PxHybridAuth\\Domain\\Model\\Identity\\' . $provider . 'Identity'; if (class_exists($identityClassName) && defined($identityClassName . '::EXTBASE_TYPE')) { $extbaseType = constant($identityClassName . '::EXTBASE_TYPE'); $this->database->exec_INSERTquery('tx_pxhybridauth_domain_model_identity', ['pid' => $user['pid'], 'tx_extbase_type' => $extbaseType, 'identifier' => $identifier, 'fe_user' => $user['uid'], 'hidden' => 0, 'deleted' => 0, 'tstamp' => time(), 'crdate' => time()]); $id = $this->database->sql_insert_id(); $where = 'uid=' . intval($id); $result = $this->database->exec_SELECTgetSingleRow('*', 'tx_pxhybridauth_domain_model_identity', $where); if ($result) { $this->database->exec_UPDATEquery('fe_users', 'uid=' . intval($user['uid']), ['tx_pxhybridauth_identities' => 1]); } } return $result; }
/** * Db add object * * @param Tx_Commerce_Dao_BasicDaoObject $object Object * * @return void */ protected function dbInsert(Tx_Commerce_Dao_BasicDaoObject &$object) { $dbTable = $this->dbTable; $dbModel = $this->parser->parseObjectToModel($object); // set pid $this->parser->setPid($dbModel, $this->createPid); // execute query $this->database->exec_INSERTquery($dbTable, $dbModel); // any errors $error = $this->database->sql_error(); if (!empty($error)) { $this->addError(array($error, $this->database->INSERTquery($dbTable, $dbModel), '$dbModel' => $dbModel)); } // set object id $object->setId($this->database->sql_insert_id()); }
/** * Inserts a new word into the search index table and returns it's UID. * If the word already exists in the search index, just the UID is returned. * @param string $word The word to be inserted * @return int The word's UID */ function wordAdd($word) { // Attempt to load word from database $res = $this->databaseHandle->exec_SELECTquery('uid', 'tx_mmforum_wordlist', "word=" . $this->databaseHandle->fullQuoteStr($word, 'tx_mmforum_wordlist') . " " . $this->getPidQuery($this->conf)); if (!$res) { echo $this->databaseHandle->sql_error() . '<hr>'; } // If words already exists, just return the UID if ($this->databaseHandle->sql_num_rows($res) > 0) { list($uid) = $this->databaseHandle->sql_fetch_row($res); } else { // Compost insert query $insertArray = array('pid' => $this->getFirstPid($this->conf), 'word' => $word, 'metaphone' => metaphone($word)); // Execute insert query $this->databaseHandle->exec_INSERTquery('tx_mmforum_wordlist', $insertArray); $uid = $this->databaseHandle->sql_insert_id(); } return $uid; }
/** * Process not yet migrated tx_news category records to sys_category records */ protected function migrateNewsCategoryRecords() { // migrate default language category records $rows = $this->databaseConnection->exec_SELECTgetRows('uid, pid, tstamp, crdate, cruser_id, starttime, endtime, sorting, ' . 'sys_language_uid, l10n_parent, l10n_diffsource, ' . 'title, description, ' . 'fe_group, single_pid, shortcut, import_id, import_source', 'tx_news_domain_model_category', 'migrate_sys_category_uid = 0 AND deleted = 0 AND sys_language_uid = 0'); if ($this->databaseConnection->sql_error()) { $message = ' SQL ERROR: ' . $this->databaseConnection->sql_error(); $status = FlashMessage::ERROR; $title = 'Failed selecting old default language category records'; $this->messageArray[] = array($status, $title, $message); } // Create a new sys_category record for each found record in default language, then $newCategoryRecords = 0; $oldNewDefaultLanguageCategoryUidMapping = array(); foreach ($rows as $row) { $oldUid = $row['uid']; unset($row['uid']); if (is_null($row['l10n_diffsource'])) { $row['l10n_diffsource'] = ''; } if (is_null($row['description'])) { $row['description'] = ''; } if ($this->databaseConnection->exec_INSERTquery('sys_category', $row) !== false) { $newUid = $this->databaseConnection->sql_insert_id(); $oldNewDefaultLanguageCategoryUidMapping[$oldUid] = $newUid; $this->databaseConnection->exec_UPDATEquery('tx_news_domain_model_category', 'uid=' . $oldUid, array('migrate_sys_category_uid' => $newUid)); $newCategoryRecords++; } else { $message = ' SQL ERROR: ' . $this->databaseConnection->sql_error(); $status = FlashMessage::ERROR; $title = 'Failed copying [' . $oldUid . '] ' . htmlspecialchars($row['title']) . ' to sys_category'; $this->messageArray[] = array($status, $title, $message); } } // migrate non-default language category records $rows = $this->databaseConnection->exec_SELECTgetRows('uid, pid, tstamp, crdate, cruser_id, starttime, endtime, sorting, ' . 'sys_language_uid, l10n_parent, l10n_diffsource, ' . 'title, description, ' . 'fe_group, single_pid, shortcut, import_id, import_source', 'tx_news_domain_model_category', 'migrate_sys_category_uid = 0 AND deleted = 0 AND sys_language_uid != 0'); if ($this->databaseConnection->sql_error()) { $message = ' SQL ERROR: ' . $this->databaseConnection->sql_error(); $status = FlashMessage::ERROR; $title = 'Failed selecting old non-default language category records'; $this->messageArray[] = array($status, $title, $message); } foreach ($rows as $row) { $oldUid = $row['uid']; unset($row['uid']); if (is_null($row['l10n_diffsource'])) { $row['l10n_diffsource'] = ''; } if (is_null($row['description'])) { $row['description'] = ''; } // set l10n_parent if category is a localized version if (array_key_exists($row['l10n_parent'], $oldNewDefaultLanguageCategoryUidMapping)) { $row['l10n_parent'] = $oldNewDefaultLanguageCategoryUidMapping[$row['l10n_parent']]; } if ($this->databaseConnection->exec_INSERTquery('sys_category', $row) !== false) { $newUid = $this->databaseConnection->sql_insert_id(); $oldNewDefaultLanguageCategoryUidMapping[$oldUid] = $newUid; $this->databaseConnection->exec_UPDATEquery('tx_news_domain_model_category', 'uid=' . $oldUid, array('migrate_sys_category_uid' => $newUid)); $newCategoryRecords++; } else { $message = ' SQL ERROR: ' . $this->databaseConnection->sql_error(); $status = FlashMessage::ERROR; $title = 'Failed copying [' . $oldUid . '] ' . htmlspecialchars($row['title']) . ' to sys_category'; $this->messageArray[] = array($status, $title, $message); } } $message = 'Created ' . $newCategoryRecords . ' sys_category records'; $status = FlashMessage::INFO; $title = ''; $this->messageArray[] = array($status, $title, $message); }
/** * * Creates a new post. * This function creates a new post. Also automatically updates all database counters. * * @author Martin Helmich * @version 2007-07-23 * @param int $topicId The UID of the topic the new post is to be created in * @param int $author The UID of the fe_user creating this post * @param string $text The post's text * @param int $date The date of post creation as unix timestamp * @param string $ip The post author's IP address * @param array $attachments An array of attachments that are to be attached * to this post. * @param boolean $noUpdate Set to TRUE in order to prevent the database counters from * being updated directly after creating this post. Instead, * the elements to be updated will be stored in an "update queue" * and will be updated after all posts/topics have been created. * This minimizes database load. * @param boolean $subscribe * @return int/boolean If post creation was successfull, the post's UID is returned, * otherwise FALSE. */ function create_post($topicId, $author, $text, $date, $ip, $attachments = array(), $noUpdate = false, $subscribe = FALSE) { $author = intval($author); // Retrieve forum uid $forumId = $this->getForumUIDByTopic($topicId); if ($forumId === false) { return false; } // Generate post record $insertArray = array('pid' => $this->getFirstPid(), 'tstamp' => $GLOBALS['EXEC_TIME'], 'crdate' => $GLOBALS['EXEC_TIME'], 'topic_id' => $topicId, 'forum_id' => $forumId, 'poster_id' => $author, 'post_time' => $date, 'poster_ip' => $ip, 'attachment' => is_array($attachments) ? implode(',', $attachments) : ''); // Include hooks if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['mm_forum']['postfactory']['insertPost'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['mm_forum']['postfactory']['insertPost'] as $_classRef) { $_procObj =& GeneralUtility::getUserObj($_classRef); $insertArray = $_procObj->processPostInsertArray($insertArray, $this); } } // Insert post record if (!$this->databaseHandle->exec_INSERTquery('tx_mmforum_posts', $insertArray)) { return false; } // Retrieve post uid $postId = $this->databaseHandle->sql_insert_id(); // Update attachment record if (is_array($attachments) && count($attachments)) { $this->databaseHandle->exec_UPDATEquery('tx_mmforum_attachments', 'uid IN (' . implode(',', $attachments) . ')', array('post_id' => $postId)); } // Generate post text record $insertArray = array('pid' => $this->getFirstPid(), 'tstamp' => $GLOBALS['EXEC_TIME'], 'crdate' => $GLOBALS['EXEC_TIME'], 'post_id' => $postId, 'post_text' => $text, 'cache_text' => $text); // Include hooks if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['mm_forum']['postfactory']['insertPostText'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['mm_forum']['postfactory']['insertPostText'] as $_classRef) { $_procObj =& GeneralUtility::getUserObj($_classRef); $insertArray = $_procObj->processPostTextInsertArray($insertArray, $this); } } // Insert post text record if (!$this->databaseHandle->exec_INSERTquery('tx_mmforum_posts_text', $insertArray)) { $this->databaseHandle->exec_DELETEquery('tx_mmforum_posts', 'uid = ' . $postId); return false; } // Clear topic for indexing if (class_exists('tx_mmforum_indexing')) { tx_mmforum_indexing::delete_topic_ind_date($topicId); } // Send notification email to users who have subscribed this topic if ($this->parent != null) { // Subscribe to the topic if ($subscribe) { $this->tx_mmforum_havealook->addSubscription($this->parent, $topicId, $author); } $this->tx_mmforum_havealook->notifyTopicSubscribers($topicId, $this->parent); } // Set topic for all users to "not read" $this->databaseHandle->exec_DELETEquery('tx_mmforum_postsread', 'topic_id = ' . $topicId); // Update topic and forum post counters if (!$noUpdate) { $this->updateTopicPostCount($topicId); $this->updateForumPostCount($forumId); $this->updateUserPostCount($author); } else { $this->updateQueue_addTopic($topicId); $this->updateQueue_addForum($forumId); $this->updateQueue_addUser($author); } return $postId; }
/** * Insert into database * Does not check permissions but expects them to be verified on beforehand * * @param string $table Record table name * @param string $id "NEW...." uid string * @param array $fieldArray Array of field=>value pairs to insert. FIELDS MUST MATCH the database FIELDS. No check is done. "pid" must point to the destination of the record! * @param bool $newVersion Set to TRUE if new version is created. * @param int $suggestedUid Suggested UID value for the inserted record. See the array $this->suggestedInsertUids; Admin-only feature * @param bool $dontSetNewIdIndex If TRUE, the ->substNEWwithIDs array is not updated. Only useful in very rare circumstances! * @return int|NULL Returns ID on success. */ public function insertDB($table, $id, $fieldArray, $newVersion = false, $suggestedUid = 0, $dontSetNewIdIndex = false) { if (is_array($fieldArray) && is_array($GLOBALS['TCA'][$table]) && isset($fieldArray['pid'])) { // Do NOT insert the UID field, ever! unset($fieldArray['uid']); if (!empty($fieldArray)) { // Check for "suggestedUid". // This feature is used by the import functionality to force a new record to have a certain UID value. // This is only recommended for use when the destination server is a passive mirror of another server. // As a security measure this feature is available only for Admin Users (for now) $suggestedUid = (int) $suggestedUid; if ($this->BE_USER->isAdmin() && $suggestedUid && $this->suggestedInsertUids[$table . ':' . $suggestedUid]) { // When the value of ->suggestedInsertUids[...] is "DELETE" it will try to remove the previous record if ($this->suggestedInsertUids[$table . ':' . $suggestedUid] === 'DELETE') { // DELETE: $this->databaseConnection->exec_DELETEquery($table, 'uid=' . (int) $suggestedUid); } $fieldArray['uid'] = $suggestedUid; } $fieldArray = $this->insertUpdateDB_preprocessBasedOnFieldType($table, $fieldArray); // Execute the INSERT query: $this->databaseConnection->exec_INSERTquery($table, $fieldArray); // If succees, do...: if (!$this->databaseConnection->sql_error()) { // Set mapping for NEW... -> real uid: // the NEW_id now holds the 'NEW....' -id $NEW_id = $id; $id = $this->databaseConnection->sql_insert_id(); if (!$dontSetNewIdIndex) { $this->substNEWwithIDs[$NEW_id] = $id; $this->substNEWwithIDs_table[$NEW_id] = $table; } $newRow = array(); // Checking the record is properly saved and writing to log if ($this->enableLogging && $this->checkStoredRecords) { $newRow = $this->checkStoredRecord($table, $id, $fieldArray, 1); } // Update reference index: $this->updateRefIndex($table, $id); if ($newVersion) { if ($this->enableLogging) { $propArr = $this->getRecordPropertiesFromRow($table, $newRow); $this->log($table, $id, 1, 0, 0, 'New version created of table \'%s\', uid \'%s\'. UID of new version is \'%s\'', 10, array($table, $fieldArray['t3ver_oid'], $id), $propArr['event_pid'], $NEW_id); } } else { if ($this->enableLogging) { $propArr = $this->getRecordPropertiesFromRow($table, $newRow); $page_propArr = $this->getRecordProperties('pages', $propArr['pid']); $this->log($table, $id, 1, 0, 0, 'Record \'%s\' (%s) was inserted on page \'%s\' (%s)', 10, array($propArr['header'], $table . ':' . $id, $page_propArr['header'], $newRow['pid']), $newRow['pid'], $NEW_id); } // Clear cache for relevant pages: $this->registerRecordIdForPageCacheClearing($table, $id); } return $id; } elseif ($this->enableLogging) { $this->log($table, $id, 1, 0, 2, 'SQL error: \'%s\' (%s)', 12, array($this->databaseConnection->sql_error(), $table . ':' . $id)); } } } return null; }
/** * Insert new record * * @return int uid of inserted record */ protected function insert() { $this->databaseConnection->exec_INSERTquery($this->getTable(), $this->getProperties()); return $this->databaseConnection->sql_insert_id(); }
/** * Creates a poll. * This static function handles the saving of a newly created * poll into the database. This includes storing the poll record * itself as well as creating the regarding answering possibilities. * * @param array $data The poll data array * @param tx_mmforum_base $pObj * @return int The newly created poll's UID * @version 2007-05-25 */ function createPoll($data, $pObj) { $defACount = $pObj->conf['polls.']['minAnswers']; if (!$pObj->conf['polls.']['enable']) { return $pObj->pi_getLL('poll.disabled'); } if (!tx_mmforum_polls::getMayCreatePoll($pObj)) { return $pObj->pi_getLL('poll.restricted'); } if (strlen(trim($data['question'])) == 0) { return $pObj->pi_getLL('poll.noQuestion'); } $answerCount = 0; foreach ($data['answer']['new'] as $answer) { if (strlen(trim($answer)) > 0) { $answerCount++; } } if ($answerCount < $defACount) { return sprintf($pObj->pi_getLL('poll.noAnswers'), $defACount); } if ($data['expires']['act']) { $expDate = mktime($data['expires']['hour'], $data['expires']['minute'], 0, $data['expires']['month'], $data['expires']['day'], $data['expires']['year']); } else { $expDate = 0; } $pollInsertData = array('pid' => $pObj->getStoragePID(), 'tstamp' => $GLOBALS['EXEC_TIME'], 'crdate' => $GLOBALS['EXEC_TIME'], 'crfeuser_id' => $GLOBALS['TSFE']->fe_user->user['uid'], 'votes' => 0, 'question' => trim($data['question']), 'endtime' => $expDate); $this->databaseHandle->exec_INSERTquery('tx_mmforum_polls', $pollInsertData); $poll_id = $this->databaseHandle->sql_insert_id(); foreach ($data['answer']['new'] as $answer) { $answer = trim($answer); if (strlen($answer) == 0) { continue; } $answerInsertData = array('pid' => $pObj->getStoragePID(), 'tstamp' => $GLOBALS['EXEC_TIME'], 'crdate' => $GLOBALS['EXEC_TIME'], 'poll_id' => $poll_id, 'votes' => 0, 'answer' => $answer); $this->databaseHandle->exec_INSERTquery('tx_mmforum_polls_answers', $answerInsertData); } return $poll_id; }
/** * @test * * @return void */ public function adminQueryReturnsTrueForDeleteQuery() { $this->assertTrue($this->subject->admin_query("INSERT INTO {$this->testTable} ({$this->testField}) VALUES ('foo')")); $id = $this->subject->sql_insert_id(); $this->assertTrue($this->subject->admin_query("DELETE FROM {$this->testTable} WHERE id={$id}")); }