@@ -74,15 +74,15 @@ discard block |
||
| 74 | 74 | public function init() |
| 75 | 75 | { |
| 76 | 76 | parent::init(); |
| 77 | - Logger::log(get_called_class() . ' init', LOG_DEBUG); |
|
| 77 | + Logger::log(get_called_class().' init', LOG_DEBUG); |
|
| 78 | 78 | $this->domain = $this->getDomain(); |
| 79 | 79 | $this->hydrateRequestData(); |
| 80 | 80 | $this->hydrateOrders(); |
| 81 | - if($this instanceof CustomApi === false) { |
|
| 81 | + if ($this instanceof CustomApi === false) { |
|
| 82 | 82 | $this->createConnection($this->getTableMap()); |
| 83 | 83 | } |
| 84 | 84 | $this->setLoaded(true); |
| 85 | - Logger::log(get_called_class() . ' loaded', LOG_DEBUG); |
|
| 85 | + Logger::log(get_called_class().' loaded', LOG_DEBUG); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | protected function hydrateOrders() |
| 92 | 92 | { |
| 93 | 93 | if (count($this->query)) { |
| 94 | - Logger::log(get_called_class() . ' gathering query string', LOG_DEBUG); |
|
| 94 | + Logger::log(get_called_class().' gathering query string', LOG_DEBUG); |
|
| 95 | 95 | foreach ($this->query as $key => $value) { |
| 96 | 96 | if ($key === self::API_ORDER_FIELD && is_array($value)) { |
| 97 | 97 | foreach ($value as $field => $direction) { |
@@ -108,10 +108,10 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | protected function extractPagination() |
| 110 | 110 | { |
| 111 | - Logger::log(get_called_class() . ' extract pagination start', LOG_DEBUG); |
|
| 111 | + Logger::log(get_called_class().' extract pagination start', LOG_DEBUG); |
|
| 112 | 112 | $page = (array_key_exists(self::API_PAGE_FIELD, $this->query)) ? $this->query[self::API_PAGE_FIELD] : 1; |
| 113 | 113 | $limit = (array_key_exists(self::API_LIMIT_FIELD, $this->query)) ? $this->query[self::API_LIMIT_FIELD] : 100; |
| 114 | - Logger::log(get_called_class() . ' extract pagination end', LOG_DEBUG); |
|
| 114 | + Logger::log(get_called_class().' extract pagination end', LOG_DEBUG); |
|
| 115 | 115 | return array($page, $limit); |
| 116 | 116 | } |
| 117 | 117 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | private function addOrders(ModelCriteria &$query) |
| 124 | 124 | { |
| 125 | - Logger::log(get_called_class() . ' extract orders start ', LOG_DEBUG); |
|
| 125 | + Logger::log(get_called_class().' extract orders start ', LOG_DEBUG); |
|
| 126 | 126 | $orderAdded = FALSE; |
| 127 | 127 | $tableMap = $this->getTableMap(); |
| 128 | 128 | foreach ($this->order->getOrders() as $field => $direction) { |
@@ -130,17 +130,17 @@ discard block |
||
| 130 | 130 | $orderAdded = TRUE; |
| 131 | 131 | if ($direction === Order::ASC) { |
| 132 | 132 | $query->addAscendingOrderByColumn($column->getPhpName()); |
| 133 | - } else { |
|
| 133 | + }else { |
|
| 134 | 134 | $query->addDescendingOrderByColumn($column->getPhpName()); |
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | if (!$orderAdded) { |
| 139 | - foreach($this->getPkDbName() as $pk => $phpName) { |
|
| 139 | + foreach ($this->getPkDbName() as $pk => $phpName) { |
|
| 140 | 140 | $query->addAscendingOrderByColumn($pk); |
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | - Logger::log(get_called_class() . ' extract orders end', LOG_DEBUG); |
|
| 143 | + Logger::log(get_called_class().' extract orders end', LOG_DEBUG); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | foreach ($this->query as $field => $value) { |
| 156 | 156 | if (self::API_COMBO_FIELD === $field) { |
| 157 | 157 | ApiHelper::composerComboField($tableMap, $query, $this->extraColumns, $value); |
| 158 | - } elseif(!preg_match('/^__/', $field)) { |
|
| 158 | + } elseif (!preg_match('/^__/', $field)) { |
|
| 159 | 159 | ApiHelper::addModelField($tableMap, $query, $field, $value); |
| 160 | 160 | } |
| 161 | 161 | } |
@@ -176,10 +176,10 @@ discard block |
||
| 176 | 176 | list($page, $limit) = $this->extractPagination(); |
| 177 | 177 | if ($limit == -1) { |
| 178 | 178 | $this->list = $query->find($this->con); |
| 179 | - } else { |
|
| 179 | + }else { |
|
| 180 | 180 | $this->list = $query->paginate($page, $limit, $this->con); |
| 181 | 181 | } |
| 182 | - } catch (\Exception $e) { |
|
| 182 | + }catch (\Exception $e) { |
|
| 183 | 183 | Logger::log($e->getMessage(), LOG_ERR); |
| 184 | 184 | } |
| 185 | 185 | } |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | $code = 200; |
| 199 | 199 | list($return, $total, $pages) = $this->getList(); |
| 200 | 200 | $message = null; |
| 201 | - if(!$total) { |
|
| 201 | + if (!$total) { |
|
| 202 | 202 | $message = i18n::_('No se han encontrado elementos para la búsqueda'); |
| 203 | 203 | } |
| 204 | 204 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | $pages = 1; |
| 225 | 225 | $message = null; |
| 226 | 226 | list($code, $return) = $this->getSingleResult($pk); |
| 227 | - if($code !== 200) { |
|
| 227 | + if ($code !== 200) { |
|
| 228 | 228 | $message = i18n::_('No se ha encontrado el elemento solicitado'); |
| 229 | 229 | } |
| 230 | 230 | |
@@ -253,13 +253,13 @@ discard block |
||
| 253 | 253 | $status = 200; |
| 254 | 254 | $saved = TRUE; |
| 255 | 255 | $model = $this->model->toArray(); |
| 256 | - } else { |
|
| 256 | + }else { |
|
| 257 | 257 | $message = i18n::_('No se ha podido guardar el modelo seleccionado'); |
| 258 | 258 | } |
| 259 | - } catch (\Exception $e) { |
|
| 260 | - $message = i18n::_('Ha ocurrido un error intentando guardar el elemento: ') .'<br>'. $e->getMessage(); |
|
| 259 | + }catch (\Exception $e) { |
|
| 260 | + $message = i18n::_('Ha ocurrido un error intentando guardar el elemento: ').'<br>'.$e->getMessage(); |
|
| 261 | 261 | $context = []; |
| 262 | - if(null !== $e->getPrevious()) { |
|
| 262 | + if (null !== $e->getPrevious()) { |
|
| 263 | 263 | $context[] = $e->getPrevious()->getMessage(); |
| 264 | 264 | } |
| 265 | 265 | Logger::log($e->getMessage(), LOG_CRIT, $context); |
@@ -295,18 +295,18 @@ discard block |
||
| 295 | 295 | $updated = TRUE; |
| 296 | 296 | $status = 200; |
| 297 | 297 | $model = $this->model->toArray(); |
| 298 | - } else { |
|
| 298 | + }else { |
|
| 299 | 299 | $message = i18n::_('Ha ocurrido un error intentando actualizar el elemento, por favor revisa los logs'); |
| 300 | 300 | } |
| 301 | - } catch (\Exception $e) { |
|
| 301 | + }catch (\Exception $e) { |
|
| 302 | 302 | $message = i18n::_('Ha ocurrido un error intentando actualizar el elemento, por favor revisa los logs'); |
| 303 | 303 | $context = []; |
| 304 | - if(null !== $e->getPrevious()) { |
|
| 304 | + if (null !== $e->getPrevious()) { |
|
| 305 | 305 | $context[] = $e->getPrevious()->getMessage(); |
| 306 | 306 | } |
| 307 | 307 | Logger::log($e->getMessage(), LOG_CRIT, $context); |
| 308 | 308 | } |
| 309 | - } else { |
|
| 309 | + }else { |
|
| 310 | 310 | $message = i18n::_('No se ha encontrado el modelo al que se hace referencia para actualizar'); |
| 311 | 311 | } |
| 312 | 312 | |
@@ -334,15 +334,15 @@ discard block |
||
| 334 | 334 | $this->con->beginTransaction(); |
| 335 | 335 | $this->hydrateModel($pk); |
| 336 | 336 | if (NULL !== $this->model) { |
| 337 | - if(method_exists('clearAllReferences', $this->model)) { |
|
| 337 | + if (method_exists('clearAllReferences', $this->model)) { |
|
| 338 | 338 | $this->model->clearAllReferences(true); |
| 339 | 339 | } |
| 340 | 340 | $this->model->delete($this->con); |
| 341 | 341 | $deleted = TRUE; |
| 342 | 342 | } |
| 343 | - } catch (\Exception $e) { |
|
| 343 | + }catch (\Exception $e) { |
|
| 344 | 344 | $context = []; |
| 345 | - if(null !== $e->getPrevious()) { |
|
| 345 | + if (null !== $e->getPrevious()) { |
|
| 346 | 346 | $context[] = $e->getPrevious()->getMessage(); |
| 347 | 347 | } |
| 348 | 348 | Logger::log($e->getMessage(), LOG_CRIT, $context); |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | $this->saveBulk(); |
| 373 | 373 | $saved = true; |
| 374 | 374 | $status = 200; |
| 375 | - } catch(\Exception $e) { |
|
| 375 | + }catch (\Exception $e) { |
|
| 376 | 376 | Logger::log($e->getMessage(), LOG_CRIT, $this->getRequest()->getData()); |
| 377 | 377 | $message = i18n::_('Bulk insert rolled back'); |
| 378 | 378 | } |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | |
| 395 | 395 | /** @var CustomerTableMap $tableMap */ |
| 396 | 396 | $modelPk = ApiHelper::extractPrimaryKeyColumnName($this->getTableMap()); |
| 397 | - foreach($this->list->getData() as $data) { |
|
| 397 | + foreach ($this->list->getData() as $data) { |
|
| 398 | 398 | $return[] = ApiHelper::mapArrayObject($this->getModelNamespace(), $modelPk, $this->query, $data); |
| 399 | 399 | } |
| 400 | 400 | return $return; |
@@ -411,20 +411,20 @@ discard block |
||
| 411 | 411 | try { |
| 412 | 412 | $this->paginate(); |
| 413 | 413 | if (null !== $this->list) { |
| 414 | - if(array_key_exists(self::API_FIELDS_RESULT_FIELD, $this->query) && Config::getParam('api.field.types')) { |
|
| 414 | + if (array_key_exists(self::API_FIELDS_RESULT_FIELD, $this->query) && Config::getParam('api.field.types')) { |
|
| 415 | 415 | $return = $this->extractDataWithFormat(); |
| 416 | - } else { |
|
| 416 | + }else { |
|
| 417 | 417 | $return = $this->list->toArray(null, false, TableMap::TYPE_PHPNAME, false); |
| 418 | 418 | } |
| 419 | 419 | $total = 0; |
| 420 | 420 | $pages = 0; |
| 421 | - if($this->list instanceof PropelModelPager) { |
|
| 421 | + if ($this->list instanceof PropelModelPager) { |
|
| 422 | 422 | $total = $this->list->getNbResults(); |
| 423 | 423 | $pages = $this->list->getLastPage(); |
| 424 | 424 | } |
| 425 | 425 | } |
| 426 | - } catch (\Exception $e) { |
|
| 427 | - Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR); |
|
| 426 | + }catch (\Exception $e) { |
|
| 427 | + Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR); |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | return array($return, $total, $pages); |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | $return = array(); |
| 443 | 443 | if (NULL === $model || !method_exists($model, 'toArray')) { |
| 444 | 444 | $code = 404; |
| 445 | - } else { |
|
| 445 | + }else { |
|
| 446 | 446 | $return = $model->toArray(TableMap::TYPE_PHPNAME, true, [], true); |
| 447 | 447 | } |
| 448 | 448 | |
@@ -95,15 +95,15 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | protected function hydrateBulkRequest() { |
| 97 | 97 | $class = new \ReflectionClass($this->getModelNamespace()); |
| 98 | - foreach($this->data as $item) { |
|
| 99 | - if(is_array($item)) { |
|
| 100 | - if(count($this->list) < Config::getParam('api.block.limit', 1000)) { |
|
| 98 | + foreach ($this->data as $item) { |
|
| 99 | + if (is_array($item)) { |
|
| 100 | + if (count($this->list) < Config::getParam('api.block.limit', 1000)) { |
|
| 101 | 101 | /** @var ActiveRecordInterface $model */ |
| 102 | 102 | $model = $class->newInstance(); |
| 103 | 103 | $this->hydrateModelFromRequest($model, $item); |
| 104 | 104 | $this->list[] = $model; |
| 105 | - } else { |
|
| 106 | - Logger::log(_('Max items per bulk insert raised'), LOG_WARNING, count($this->data) . _('items')); |
|
| 105 | + }else { |
|
| 106 | + Logger::log(_('Max items per bulk insert raised'), LOG_WARNING, count($this->data)._('items')); |
|
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | } |
@@ -114,12 +114,12 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | protected function saveBulk() { |
| 116 | 116 | $tablemap = $this->getTableMap(); |
| 117 | - foreach($this->list as &$model) { |
|
| 117 | + foreach ($this->list as &$model) { |
|
| 118 | 118 | $con = Propel::getWriteConnection($tablemap::DATABASE_NAME); |
| 119 | 119 | try { |
| 120 | 120 | $model->save($con); |
| 121 | 121 | $con->commit(); |
| 122 | - } catch(\Exception $e) { |
|
| 122 | + }catch (\Exception $e) { |
|
| 123 | 123 | Logger::log($e->getMessage(), LOG_ERR, $model->toArray()); |
| 124 | 124 | $con->rollBack(); |
| 125 | 125 | } |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | protected function exportList() { |
| 133 | 133 | $list = []; |
| 134 | 134 | /** @var ActiveRecordInterface $item */ |
| 135 | - foreach($this->list as $item) { |
|
| 135 | + foreach ($this->list as $item) { |
|
| 136 | 136 | $list[] = $item->toArray(); |
| 137 | 137 | } |
| 138 | 138 | return $list; |
@@ -156,16 +156,16 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | protected function findPk(ModelCriteria $query, $pk) { |
| 158 | 158 | $pks = explode(Api::API_PK_SEPARATOR, urldecode($pk)); |
| 159 | - if(count($pks) === 1 && !empty($pks[0])) { |
|
| 159 | + if (count($pks) === 1 && !empty($pks[0])) { |
|
| 160 | 160 | $query->filterByPrimaryKey($pks[0]); |
| 161 | - } else { |
|
| 161 | + }else { |
|
| 162 | 162 | $i = 0; |
| 163 | - foreach($this->getPkDbName() as $key => $phpName) { |
|
| 163 | + foreach ($this->getPkDbName() as $key => $phpName) { |
|
| 164 | 164 | try { |
| 165 | 165 | $query->filterBy($phpName, $pks[$i]); |
| 166 | 166 | $i++; |
| 167 | - if($i >= count($pks)) break; |
|
| 168 | - } catch(\Exception $e) { |
|
| 167 | + if ($i >= count($pks)) break; |
|
| 168 | + }catch (\Exception $e) { |
|
| 169 | 169 | Logger::log($e->getMessage(), LOG_DEBUG); |
| 170 | 170 | } |
| 171 | 171 | } |
@@ -195,8 +195,8 @@ discard block |
||
| 195 | 195 | try { |
| 196 | 196 | $query = $this->prepareQuery(); |
| 197 | 197 | $this->model = $this->findPk($query, $pk); |
| 198 | - } catch (\Exception $e) { |
|
| 199 | - Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR); |
|
| 198 | + }catch (\Exception $e) { |
|
| 199 | + Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR); |
|
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | |