public function executeDelete() { $token = mfwRequest::param('token', null, 'POST'); if ($token !== mfwSession::get(self::SESKEY_TOKEN)) { return $this->buildErrorPage('Bad Request', array(self::HTTP_400_BADREQUEST)); } mfwSession::clear(self::SESKEY_TOKEN); $con = mfwDBConnection::getPDO(); $con->beginTransaction(); try { $this->app = ApplicationDb::retrieveByPKForUpdate($this->app->getId()); $this->package->delete($con); if ($this->app->getLastUpload() == $this->package->getCreated()) { // 最終アップデート時刻を前のものに戻す $pkg = PackageDb::selectNewestOneByAppId($this->app->getId()); $lastupload = $pkg ? $pkg->getCreated() : null; $this->app->updateLastUpload($lastupload, $con); } $con->commit(); } catch (Exception $e) { $con->rollback(); error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}"); throw $e; } apache_log('app_id', $this->app->getId()); apache_log('pkg_id', $this->package->getId()); apache_log('platform', $this->package->getPlatform()); try { $this->package->deleteFile(); } catch (Exception $e) { // S3から削除出来なくてもDBからは消えているので許容する } return $this->redirect("/app?id={$this->app->getId()}"); }
/** * make prepared statement. * @param[in] $sql 実行するSQL * @param[in] $con DB connection (PDO) * @return PDOStatement */ public static function prepare($sql, PDO $con = null) { if (!$con) { $con = mfwDBConnection::getPDO(); } return $con->prepare($sql); }
public function executeInstall() { $pf = $this->package->getPlatform(); $ua = mfwRequest::userAgent(); if ($pf === Package::PF_IOS && $ua->isIOS()) { // itms-service での接続はセッションを引き継げない // 一時トークンをURLパラメータに付けることで認証する $scheme = Config::get('enable_https') ? 'https' : null; // HTTPSが使えるならHTTPS優先 $plist_url = mfwHttp::composeUrl(mfwRequest::makeUrl('/package/install_plist', $scheme), array('id' => $this->package->getId(), 't' => $this->makeToken())); $url = 'itms-services://?action=download-manifest&url=' . urlencode($plist_url); } else { // iPhone以外でのアクセスはパッケージを直接DL $url = $this->package->getFileUrl('+60 min'); } $con = mfwDBConnection::getPDO(); $con->beginTransaction(); try { InstallLog::Logging($this->login_user, $this->package, $ua, $con); $con->commit(); } catch (Exception $e) { $con->rollback(); error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}"); throw $e; } apache_log('app_id', $this->app->getId()); apache_log('pkg_id', $this->package->getId()); apache_log('platform', $this->package->getPlatform()); return $this->redirect($url); }
public function executeUpload_post() { $temp_name = mfwRequest::param('temp_name'); $platform = mfwRequest::param('platform'); $title = mfwRequest::param('title'); $description = mfwRequest::param('description'); $tag_names = mfwRequest::param('tags'); $ios_identifier = mfwRequest::param('ios_identifier'); $notify = mfwRequest::param('notify'); $org_filename = mfwRequest::param('file_name'); $filesize = mfwRequest::param('file_size'); if (!$temp_name || !$title) { error_log(__METHOD__ . '(' . __LINE__ . "): bad request: {$temp_name}, {$title}"); return $this->response(self::HTTP_400_BADREQUEST); } $ext = pathinfo($temp_name, PATHINFO_EXTENSION); $con = mfwDBConnection::getPDO(); $con->beginTransaction(); try { $app = ApplicationDb::retrieveByPKForUpdate($this->app->getId(), $con); $tags = $app->getTagsByName($tag_names, $con); $pkg = PackageDb::insertNewPackage($this->app->getId(), $platform, $ext, $title, $description, $ios_identifier, $org_filename, $filesize, $tags, $con); $pkg->renameTempFile($temp_name); $app->updateLastUpload($pkg->getCreated(), $con); $con->commit(); } catch (Exception $e) { error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}"); $con->rollback(); throw $e; } if ($notify) { try { $users = $app->getInstallUsers(); $users->noticePackageUploaded($pkg); } catch (Exception $e) { // アップロード通知が送れなくても許容する error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}"); } } apache_log('app_id', $app->getId()); apache_log('pkg_id', $pkg->getId()); return $this->redirect("/package?id={$pkg->getId()}"); }
public function executeComment_post() { $message = mfwRequest::param('message'); $package_id = mfwRequest::param('package_id'); $con = mfwDBConnection::getPDO(); $con->beginTransaction(); try { $this->app = ApplicationDb::retrieveByPkForUpdate($this->app->getId()); $comment = CommentDb::post($this->login_user, $this->app, $package_id, $message); $this->app->updateLastCommented($comment->getCreated()); $con->commit(); } catch (Exception $e) { error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}"); $con->rollback(); throw $e; } $owners = $this->app->getOwners(); $owners->noticeNewComment($comment, $this->app); return $this->redirect('/app/comment', array('id' => $this->app->getId())); }
public function executeDelete() { $con = null; try { $api_key = mfwRequest::param('api_key'); $pkg_id = mfwRequest::param('id'); $app = ApplicationDb::selectByApiKey($api_key); if (!$app) { return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'Invalid api_key')); } $pkg = PackageDb::retrieveByPK($pkg_id); if (!$pkg || $app->getId() !== $pkg->getAppId()) { return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'Invalid package id')); } $con = mfwDBConnection::getPDO(); $con->beginTransaction(); $app = ApplicationDb::retrieveByPKForUpdate($app->getId(), $con); $pkg->delete($con); if ($app->getLastUpload() == $pkg->getCreated()) { // 最終アップデート時刻を前のものに戻す $pkg = PackageDb::selectNewestOneByAppId($app->getId()); $lastupload = $pkg ? $pkg->getCreated() : null; $app->updateLastUpload($lastupload, $con); } $con->commit(); } catch (Exception $e) { if ($con) { $con->rollback(); } error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}"); return $this->jsonResponse(self::HTTP_500_INTERNALSERVERERROR, array('error' => $e->getMessage(), 'exception' => get_class($e))); } try { $pkg->deleteFile(); } catch (Exception $e) { // S3から削除出来なくてもDBからは消えているので許容する } apache_log('app_id', $app->getId()); apache_log('pkg_id', $pkg->getId()); return $this->jsonResponse(self::HTTP_200_OK, $this->makePackageArray($pkg)); }
public function executeEdit_commit() { $title = mfwRequest::param('title'); $description = mfwRequest::param('description'); $tag_names = mfwRequest::param('tags'); if (!$title) { error_log(__METHOD__ . '(' . __LINE__ . "): bad request: {$temp_name}, {$title}"); return $this->response(self::HTTP_400_BADREQUEST); } $con = mfwDBConnection::getPDO(); $con->beginTransaction(); try { $app = ApplicationDb::retrieveByPKForUpdate($this->app->getId(), $con); $tags = $app->getTagsByName($tag_names, $con); $pkg = PackageDb::retrieveByPKForUpdate($this->package->getId(), $con); $pkg->updateInfo($title, $description, $tags); $con->commit(); } catch (Exception $e) { $con->rollback(); throw $e; } return $this->redirect("/package?id={$this->package->getId()}"); }
public function executeCreate() { $title = mfwRequest::param('title'); $data = mfwRequest::param('icon-data'); $description = mfwRequest::param('description'); $repository = mfwRequest::param('repository'); if (!$title || !preg_match('/^data:[^;]+;base64,(.+)$/', $data, $match)) { error_log(__METHOD__ . '(' . __LINE__ . "): bad request: {$title}, " . substr($data, 0, 30)); return $this->response(self::HTTP_400_BADREQUEST); } $image = base64_decode($match[1]); $con = mfwDBConnection::getPDO(); $con->beginTransaction(); try { $app = ApplicationDb::insertNewApp($this->login_user, $title, $image, $description, $repository); $con->commit(); } catch (Exception $e) { error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}"); $con->rollback(); throw $e; } apache_log('app_id', $app->getId()); return $this->redirect("/app?id={$app->getId()}"); }
public function executeUpload() { $con = null; try { if (mfwRequest::method() !== 'POST') { return $this->jsonResponse(self::HTTP_405_METHODNOTALLOWED, array('error' => 'Method Not Allowed')); } $api_key = mfwRequest::param('api_key'); $file_info = mfwRequest::param('file'); $title = mfwRequest::param('title'); $description = mfwRequest::param('description'); $notify = mfwRequest::param('notify'); $tag_names = explode(',', mfwRequest::param('tags')); if (!$api_key || !$file_info || !$title) { return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'A required field is not present.')); } if (!isset($file_info['error']) || $file_info['error'] !== UPLOAD_ERR_OK) { error_log(__METHOD__ . '(' . __LINE__ . '): upload file error: $_FILES[file]=' . json_encode($file_info)); return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'upload file error: $_FILES[file]=' . json_encode($file_info))); } $app = ApplicationDb::selectByApiKey($api_key); if (!$app) { return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'Invalid api_key')); } apache_log('app_id', $app->getId()); // ファイルフォーマット確認, 情報抽出 list($platform, $ext, $mime) = PackageDb::getPackageInfo($file_info['name'], $file_info['tmp_name'], $file_info['type']); $ios_identifier = null; if ($platform === Package::PF_IOS) { $plist = IPAFile::parseInfoPlist($file_info['tmp_name']); $ios_identifier = $plist['CFBundleIdentifier']; } // DBへ保存 $con = mfwDBConnection::getPDO(); $con->beginTransaction(); $app = ApplicationDb::retrieveByPKForUpdate($app->getId()); $tags = $app->getTagsByName($tag_names, $con); $pkg = PackageDb::insertNewPackage($app->getId(), $platform, $ext, $title, $description, $ios_identifier, $file_info['name'], $file_info['size'], $tags, $con); apache_log('pkg_id', $pkg->getId()); // S3へアップロード $pkg->uploadFile($file_info['tmp_name'], $mime); $app->updateLastUpload($pkg->getCreated(), $con); $con->commit(); } catch (Exception $e) { if ($con) { $con->rollback(); } error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}"); return $this->jsonResponse(self::HTTP_500_INTERNALSERVERERROR, array('error' => $e->getMessage(), 'exception' => get_class($e))); } if ($notify) { try { $users = $app->getInstallUsers(); $users->noticePackageUploaded($pkg); } catch (Exception $e) { // アップロード通知が送れなくても許容する error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}"); } } return $this->jsonResponse(self::HTTP_200_OK, $this->makePackageArray($pkg)); }
public static function disconnect() { self::$con_pool = array(); }
} } } } } /*---------------------------------------------------------------------------- * DBに登録 */ // filterマッチしなかったものを先にupdate foreach ($cursorlist as $rid => $cursor) { if (!isset($alerted_pulls[$rid])) { RepositoryDb::updateCursor($rid, $cursor); } } // アラートがあるものはrepo毎のトランザクションで一括保存 $con = mfwDBConnection::getPDO('default_master'); $repoids = array_keys($alerted_pulls); foreach ($repoids as $rid) { echo "save: {$repos[$rid]->getName()} ... "; $con->beginTransaction(); try { foreach ($alerts[$rid] as $alert) { $pra = new PullRequestAlert($alert); $pra->save($con); } foreach ($alerted_pulls[$rid] as $p) { $pr = new PullRequest(array('repo_id' => $rid, 'number' => $p['number'], 'user' => $p['user']['login'], 'title' => $p['title'], 'pull_created_at' => $p['created_at'])); $pr->save($con); } RepositoryDb::updateCursor($rid, $cursorlist[$rid], $con); $con->commit();
public function executePreferences_update_owners() { $owners = mfwRequest::param('owners'); $owners = array_filter($owners, 'strlen'); // 自分自身は除外させない $owners[] = $this->login_user->getMail(); $owners = array_unique($owners); $con = mfwDBConnection::getPDO(); $con->beginTransaction(); try { $this->app = ApplicationDb::retrieveByPkForUpdate($this->app->getId(), $con); $this->app->setOwners($owners, $con); $con->commit(); } catch (Exception $e) { error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}"); $con->rollback(); throw $e; } return $this->redirect("/app/preferences?id={$this->app->getId()}#owners"); }
/** * 単一オブジェクトのレコードをinsert. */ public static function insert(mfwObject $obj, $con = null) { $table = static::TABLE_NAME; $row = $obj->toArray(); $columns = '`' . implode('`,`', array_keys($row)) . '`'; $places = implode(',', array_fill(0, count($row), '?')); $sql = "INSERT INTO `{$table}` ({$columns}) VALUES ({$places})"; $bind = array_values($row); $con = $con ?: mfwDBConnection::getPDO(); mfwDBIBase::query($sql, $bind, $con); return $con->lastInsertId(); }