public function serveSet($funct, $par, Model $model) { $content = $model->getContent(); $struct = $this->getStruct(); $tmps =& $struct; $data =& $content; $temp =& $data; foreach ($funct as $k) { $tmps =& $tmps[$k]; $temp =& $temp[$k]; } $this->modelChecker->newTest(); if (isset($tmps) && !is_array($tmps) && $this->modelChecker->isValidValue($par, $tmps, implode('_', $funct))) { $temp = $par; $model->setContent($data); return true; } else { $this->corrupt = true; return false; } }
/** * Elimina il Model dalla base di dati in base all' id fornendo la versione * corretta * * @param Model $model * @return bool <b>boolean</b> in base alla avvenuta cancellazione * @throws GraphException * @internal param $ <b>Model</b> model da eliminare [id e versione obbligatori]* <b>Model</b> model da eliminare [id e versione obbligatori] */ public function delete(Model $model) { Log::debug('calling storage driver for delete'); if ($model->getId() == null) { throw new GraphException('Unavailable ' . $model->getModelName() . ' id', ExceptionsCodes::BEAN_STORAGE_ID_UNAVAILABLE, 400); } if ($model->getVersion() == null) { throw new GraphException('Unavailable ' . $model->getModelName() . ' version', ExceptionsCodes::BEAN_STORAGE_VERSION_UNAVAILABLE, 500); } if (!$model->isValid()) { throw new GraphException('Error on storage, ' . $model->getModelName() . ' is corrupt: ' . $model->getLastTestErrors(), ExceptionsCodes::BEAN_STORAGE_CORRUPTED_BEAN, 500); } $bkpContent = $model->getContent(); $model->setLazy(true); $model->setContent(array('id' => $bkpContent['id'])); $readed = $this->read($model); if ($readed == null) { throw new GraphException($model->getModelName() . ' not found', ExceptionsCodes::BEAN_STORAGE_ID_NOT_FOUND, 404); } if ($readed->getVersion() != $bkpContent['version']) { throw new GraphException($model->getModelName() . ' version Mismatch, reload model for updates', ExceptionsCodes::BEAN_STORAGE_VERSION_MISMATCH, 400); } $model->setContent($bkpContent); $this->driver->delete($this->serializeForDb($model)); return true; }