/** * Run logic * @param array $args * @return bool * @throws \Jazz\Command\Exception\ExecutionFailure */ protected function _run(array $args) { parent::_run($args); /* @var $model \Jazz\IModel */ $ret = false; $model = $args['model']; if ($model->data()->isModified()) { $query = \Jazz\Model::factory()->query($model->name()); $data = array(); $id = null; if ($model->data()->isLoaded()) { if ($query instanceof \Jazz\Model\Query\IUpdate) { $query->update($model->primary(), $this->_filterDataToSave($model)); $id = $model->primary(); } } else { if ($query instanceof \Jazz\Model\Query\IInsert) { $id = $query->insert($this->_filterDataToSave($model)); } } if ($query instanceof \Jazz\Model\Query\ISelect && $id !== null) { $data = $query->select($id); } $model->populate($data); $ret = true; } return $ret; }
/** * Run logic * @param array $args * @throws \Jazz\Command\Exception\ExecutionFailure */ protected function _run(array $args) { parent::_run($args); // verify LIST $list = $args['list']; if (!is_array($list) || empty($list)) { throw new \Jazz\Command\Exception\Failure('Invalid LIST'); } $model = $args['model']; $list = $model->structure()->swapColumnsForKeys($list); foreach ($list as $key => $val) { $model->set($key, $val); } }
/** * Run logic * @param array $args * @return bool * @throws \Jazz\Command\Exception\ExecutionFailure */ protected function _run(array $args) { parent::_run($args); /* @var $model \Jazz\IModel */ $ret = false; $model = $args['model']; if ($model->data()->isLoaded()) { $query = \Jazz\Model::factory()->query($model->name()); if ($query instanceof \Jazz\Model\Query\IDelete) { $query->delete($model->data()->primary()); $ret = true; } } $model->clear(); return $ret; }
/** * Run logic * @param array $args * @return bool * @throws \Jazz\Command\Exception\ExecutionFailure */ protected function _run(array $args) { parent::_run($args); $col = \Jazz\Model::factory()->collection($args['type']); $col->setType($args['type']); $col->setClass($args['type']); if ($args['reference'] !== null) { $col->setKey($args['reference']); } $callback = $col->getCallback(); $callback->setArgs($args['args']); if (is_string($callback)) { $callback->setMethod($callback); } else { if (is_array($callback)) { $callback->setMethod($callback[1], \Jazz\Model::factory()->query($callback[0])); } } return $col; }
/** * Run logic * @param array $args * @return bool * @throws \Jazz\Command\Exception\ExecutionFailure */ protected function _run(array $args) { parent::_run($args); // verify ID $id = $args['id']; if ($id !== null && !is_numeric($id) && !is_string($id)) { throw new \Jazz\Command\Exception\Failure('Invalid ID'); } // verify readOnly $readOnly = $args['readOnly']; if (!is_bool($readOnly)) { $readOnly = false; } /* @var $model \Jazz\IModel */ $model = $args['model']; $data = array(); $query = \Jazz\Model::factory()->query($model->name()); if ($query instanceof \Jazz\Model\Query\ISelect) { $data = $query->select($id); } $model->populate($data, $readOnly); return !empty($data); }
/** * Run logic * @param array $args * @return bool * @throws \Jazz\Command\Exception\ExecutionFailure */ protected function _run(array $args) { parent::_run($args); return \Jazz\Model::factory()->model($args['type'], $args['id']); }