예제 #1
0
 private function installApi(Module $module, $data, $actionMap)
 {
     if (!isset($data['api'])) {
         return;
     }
     if (!isset($data['api']['apis'])) {
         return;
     }
     $base = '/';
     if (isset($data['api']['resourcePath'])) {
         $base = $data['api']['resourcePath'];
     }
     foreach ($data['api']['apis'] as $apis) {
         $path = $apis['path'];
         foreach ($apis['operations'] as $op) {
             // fetch required params
             $required = [];
             if (isset($op['parameters'])) {
                 foreach ($op['parameters'] as $param) {
                     if (isset($param['paramType']) && $param['paramType'] == 'path') {
                         $required[] = $param['name'];
                     }
                 }
             }
             // create record
             $fullPath = str_replace('//', '/', $base . '/' . $path);
             $api = new Api();
             $api->setMethod($op['method']);
             $api->setRoute($fullPath);
             $api->setActionId($actionMap[$op['nickname']]);
             $api->setRequiredParams(implode(',', $required));
             $api->save();
         }
     }
     $module->setApi(true);
     $module->save();
 }
예제 #2
0
 private function updateApi(Module $model, ModuleSchema $module, $actions)
 {
     $repo = $this->service->getResourceRepository();
     $filename = sprintf('/packages/%s/api.json', $model->getName());
     if (!$repo->contains($filename)) {
         return;
     }
     // delete every api existent for the given module prior to create the new ones
     ApiQuery::create()->filterByActionId(array_values($actions))->delete();
     // 		$extensions = $this->service->getExtensionRegistry()->getExtensionsByPackage('keeko.api', $model->getName());
     $json = Json::decode($repo->get($filename)->getBody());
     $swagger = new Swagger($json);
     foreach ($swagger->getPaths() as $path) {
         /* @var $path Path */
         foreach (Swagger::$METHODS as $method) {
             if ($path->hasOperation($method)) {
                 $op = $path->getOperation($method);
                 $actionName = $op->getOperationId();
                 if (!isset($actions[$actionName])) {
                     continue;
                 }
                 // find required parameters
                 $required = [];
                 foreach ($op->getParameters() as $param) {
                     /* @var $param Parameter */
                     if ($param->getIn() == 'path' && $param->getRequired()) {
                         $required[] = $param->getName();
                     }
                 }
                 // 					$prefix = isset($extensions[$actionName])
                 // 						? $extensions[$actionName]
                 // 						: $module->getSlug();
                 $prefix = $module->getSlug();
                 $fullPath = str_replace('//', '/', $prefix . '/' . $path->getPath());
                 $api = new Api();
                 $api->setMethod($method);
                 $api->setRoute($fullPath);
                 $api->setActionId($actions[$actionName]);
                 $api->setRequiredParams(implode(',', $required));
                 $api->save();
             }
         }
     }
     $model->setApi(true);
     $model->save();
 }
예제 #3
0
파일: Action.php 프로젝트: keeko/core
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      ConnectionInterface $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see save()
  */
 protected function doSave(ConnectionInterface $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aModule !== null) {
             if ($this->aModule->isModified() || $this->aModule->isNew()) {
                 $affectedRows += $this->aModule->save($con);
             }
             $this->setModule($this->aModule);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
                 $affectedRows += 1;
             } else {
                 $affectedRows += $this->doUpdate($con);
             }
             $this->resetModified();
         }
         if ($this->groupsScheduledForDeletion !== null) {
             if (!$this->groupsScheduledForDeletion->isEmpty()) {
                 $pks = array();
                 foreach ($this->groupsScheduledForDeletion as $entry) {
                     $entryPk = [];
                     $entryPk[1] = $this->getId();
                     $entryPk[0] = $entry->getId();
                     $pks[] = $entryPk;
                 }
                 \keeko\core\model\GroupActionQuery::create()->filterByPrimaryKeys($pks)->delete($con);
                 $this->groupsScheduledForDeletion = null;
             }
         }
         if ($this->collGroups) {
             foreach ($this->collGroups as $group) {
                 if (!$group->isDeleted() && ($group->isNew() || $group->isModified())) {
                     $group->save($con);
                 }
             }
         }
         if ($this->apisScheduledForDeletion !== null) {
             if (!$this->apisScheduledForDeletion->isEmpty()) {
                 \keeko\core\model\ApiQuery::create()->filterByPrimaryKeys($this->apisScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->apisScheduledForDeletion = null;
             }
         }
         if ($this->collApis !== null) {
             foreach ($this->collApis as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->groupActionsScheduledForDeletion !== null) {
             if (!$this->groupActionsScheduledForDeletion->isEmpty()) {
                 \keeko\core\model\GroupActionQuery::create()->filterByPrimaryKeys($this->groupActionsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->groupActionsScheduledForDeletion = null;
             }
         }
         if ($this->collGroupActions !== null) {
             foreach ($this->collGroupActions as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }