Beispiel #1
0
 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()}");
 }
Beispiel #2
0
 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));
 }