/** * Looks if the specified table exists and if not create it with the key- * field (uid). Then it syncs the DB-fields with the fields found in the form * with help of template parser */ protected function createTable() { $fields = $this->getFormFields(); if ($this->settings['excludeFields']) { $excludes = t3lib_div::trimExplode(',', $this->settings['excludeFields']); foreach ($excludes as $exclude) { unset($fields[$exclude]); } } if (Tx_Formhandler_Globals::$settings['debug']) { $this->db->debugOutput = 1; } $res = $this->db->sql_query("SHOW TABLES LIKE '" . $this->table . "'"); if (!$this->db->sql_num_rows($res)) { $query = "CREATE TABLE `" . $this->table . "` (\n\t\t\t\t`" . $this->key . "` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY\n\t\t\t)"; $this->db->sql_query($query); Tx_Formhandler_StaticFuncs::debugMessage('sql_request', array($query)); $dbFields = array($this->key); } else { $dbFields = array_keys($this->db->admin_get_fields($this->table)); } $createFields = array_diff($fields, $dbFields); if (count($createFields)) { $sql = 'ALTER TABLE ' . $this->table . ' ADD `'; $sql .= implode('` ' . $this->newFieldsSqlAttribs . ', ADD `', $createFields); $sql .= '` ' . $this->newFieldsSqlAttribs . ''; $this->db->sql_query($sql); Tx_Formhandler_StaticFuncs::debugMessage('sql_request', array($sql)); if ($this->db->sql_error()) { Tx_Formhandler_StaticFuncs::debugMessage('error', array($this->db->sql_error()), 3); } } }
/** * Checks if there are SQL errors in the last query, and if yes, throw an exception. * * @return void * @param string $sql The SQL statement * @throws Tx_Extbase_Persistence_Storage_Exception_SqlError */ protected function checkSqlErrors($sql = '') { $error = $this->databaseHandle->sql_error(); if ($error !== '') { $error .= $sql ? ': ' . $sql : ''; throw new Tx_Extbase_Persistence_Storage_Exception_SqlError($error, 1247602160); } }
/** * This should only be used for a remote system! * Clears the cache for the given root. * Note: There must be a sys_domain record in the given rootline! (This does not work for root = 0!). * * @param int $root The root to clear from. * @param boolean $clearAll Whether to clear all caches. * @return void * @throws Exception */ public function clearCache($root, $clearAll = false) { $domain = $this->getDomain($root); if ($clearAll) { $content = 'ALL'; } else { $pids = $this->getPageTreeUids($root); $content = is_array($pids) ? implode(',', $pids) : ''; } if (empty($content) || $domain === null) { // do nothing return; } $hash = t3lib_div::getRandomHexString(32); $fields = array('identifier' => $hash, 'crdate' => time(), 'content' => serialize($content), 'lifetime' => 120, 'expires' => time() + 120); foreach (t3lib_div::trimExplode(',', self::CACHE_TABLES, true) as $table) { $res = $this->db->sql_query('SHOW TABLES LIKE \'' . $table . '\''); if ($this->db->sql_num_rows($res) > 0) { break; } } if ($table === 'cf_cache_hash') { unset($fields['crdate']); unset($fields['lifetime']); } else { unset($fields['expires']); } $this->db->exec_INSERTquery($table, $fields); $sqlError = $this->db->sql_error(); if (!empty($sqlError)) { throw new Exception($sqlError, 1356616552); } $url = $domain . 'index.php?eID=tx_contentstage&hash=' . $hash; $ch = curl_init($url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); $extensionConfiguration = $this->getParent()->getExtensionConfiguration(); $sslVersion = intval($extensionConfiguration['remote.']['sslVersion']); if ($sslVersion === 2 || $sslVersion === 3) { curl_setopt($ch, CURLOPT_SSLVERSION, $sslVersion); } $result = curl_exec($ch); $data = json_decode($result); if (empty($data->success)) { $errors = array_map(function ($value) { return $value->message; }, $data->errors); throw new Exception('[' . $url . '] ' . implode(', ', $errors), 1356616552); } }