/** * 書き込みデータの保存形式を変更する * * @param string $post_db_path * @return void */ function _100120_0700_convert_post_data_store($post_db_path) { if (!file_exists($post_db_path)) { return; } $oldKvs = P2KeyValueStore::getStore($post_db_path, P2KeyValueStore::CODEC_SERIALIZING); $newKvs = PostDataStore::getKVS(); foreach ($oldKvs as $key => $value) { $newKvs->set($key, $value); } if ($oldKvs->getTableName() != $newKvs->getTableName()) { $oldKvs->prepare('DROP TABLE $__table')->execute(); } // プリペアードステートメントを破棄するために optimize() $newKvs->optimize(); }
/** * データを保存するP2KeyValueStoreオブジェクトを取得する * * @param string $databasePath * @param string $codec * @param string $tableName * @return P2KeyValueStore */ protected static function _getKVS($databasePath, $codec = P2KeyValueStore::CODEC_SERIALIZING, $tableName = null) { global $_conf; $id = $codec . ':' . $databasePath; if (array_key_exists($id, self::$_kvs)) { return self::$_kvs[$id]; } if (!file_exists($databasePath) && !is_dir(dirname($databasePath))) { FileCtl::mkdirFor($databasePath); } try { $kvs = P2KeyValueStore::getStore($databasePath, $codec, $tableName); self::$_kvs[$id] = $kvs; } catch (Exception $e) { p2die(get_class($e) . ': ' . $e->getMessage()); } return $kvs; }
/** * cachedGetHostByAddr/cachedGetHostByName のキャッシュエンジン */ private static function _cachedGetHost($remote, $function) { global $_conf; $lifeTime = (int) $GLOBALS['_HOSTCHKCONF']['gethostby_lifetime']; if ($lifeTime <= 0) { return $function($remote); } if (!file_exists($_conf['hostcheck_db_path'])) { FileCtl::mkdirFor($_conf['hostcheck_db_path']); } $kvs = P2KeyValueStore::getStore($_conf['hostcheck_db_path']); $result = $kvs->get($remote, $lifeTime); if ($result !== null) { return $result; } $result = $function($remote); $kvs->set($remote, $result); return $result; }
break; // データベースを最適化する // データベースを最適化する case 'optimizeDB': // SQLite2 の画像キャッシュデータベースをVACUUM if ($db->dsn['phptype'] == 'sqlite') { $result = $db->query('VACUUM'); if (DB::isError($result)) { P2Util::pushInfoHtml($result->getMessage()); } else { P2Util::pushInfoHtml('<p>画像データベースを最適化しました。</p>'); } } // SQLite3 の一覧表示用データキャッシュをVACUUM,REINDX if ($viewer_cache_exists) { $kvs = P2KeyValueStore::getStore($_conf['iv2_cache_db_path'], P2KeyValueStore::CODEC_SERIALIZING); $kvs->optimize(); unset($kvs); P2Util::pushInfoHtml('<p>一覧表\示用のデータキャッシュを最適化しました。</p>'); } break; // 未定義のリクエスト // 未定義のリクエスト default: P2Util::pushInfoHtml('<p>未定義のリクエストです。</p>'); } if (isset($removed_files)) { $flexy->setData('removedFiles', $removed_files); } } // }}}
/** * コンストラクタ * * @param string $rootUri * @param string $loginId * @param string $loginPass * @param string $cookieSaveDir * @param bool $ignoreCookieAddr * @throws P2Exception */ public function __construct($rootUri, $loginId, $loginPass, $cookieSaveDir, $ignoreCookieAddr = false) { if (!preg_match('!^https?://.+/$!', $rootUri)) { throw new Exception('Invalid root URI was given.'); } $this->_rootUri = $rootUri; try { $cookieSavePath = $cookieSaveDir . DIRECTORY_SEPARATOR . self::COOKIE_STORE_NAME; $cookieStore = P2KeyValueStore::getStore($cookieSavePath, P2KeyValueStore::CODEC_SERIALIZING); } catch (Exception $e) { throw new P2Exception(get_class($e) . ': ' . $e->getMessage()); } if ($cookieManager = $cookieStore->get($loginId)) { if (!$cookieManager instanceof HTTP_Client_CookieManager) { $cookieStore->delete($loginId); throw new Exception('Cannot restore the cookie manager.'); } } else { $cookieManager = new HTTP_Client_CookieManager(); } $this->_loginId = $loginId; $this->_loginPass = $loginPass; $this->_cookieStore = $cookieStore; $this->_cookieManager = $cookieManager; $this->_ignoreCookieAddr = $ignoreCookieAddr; $defaultHeaders = array('User-Agent' => self::HTTP_USER_AGENT); $this->_httpClient = new HTTP_Client(null, $defaultHeaders, $cookieManager); }