/** * Try to acquire a new process with the given id * also performs some auto-cleanup for orphan processes * @todo preemption might not be the most elegant way to clean up * * @param string $id identification string for the process * @return boolean determines whether the attempt to get resources was successful */ function CLI_checkAndAcquireNewProcess($id) { $ret = true; $processCount = 0; $orphanProcesses = array(); $this->db->sql_query('BEGIN'); $res = $this->db->exec_SELECTquery('process_id,ttl', 'tx_crawler_process', 'active=1 AND deleted=0'); $currentTime = $this->getCurrentTime(); while ($row = $this->db->sql_fetch_assoc($res)) { if ($row['ttl'] < $currentTime) { $orphanProcesses[] = $row['process_id']; } else { $processCount++; } } // if there are less than allowed active processes then add a new one if ($processCount < intval($this->extensionSettings['processLimit'])) { $this->CLI_debug("add " . $this->CLI_buildProcessId() . " (" . ($processCount + 1) . "/" . intval($this->extensionSettings['processLimit']) . ")"); // create new process record $this->db->exec_INSERTquery('tx_crawler_process', array('process_id' => $id, 'active' => '1', 'ttl' => $currentTime + intval($this->extensionSettings['processMaxRunTime']))); } else { $this->CLI_debug("Processlimit reached (" . $processCount . "/" . intval($this->extensionSettings['processLimit']) . ")"); $ret = false; } $this->CLI_releaseProcesses($orphanProcesses, true); // maybe this should be somehow included into the current lock $this->db->sql_query('COMMIT'); return $ret; }
/** * 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); } }