/** * Delete news * * @param Repository $repo * @param NewsCategoryEntity $entity * @return boolean * @throws \RuntimeException */ public function delete(Repository $repo, NewsCategoryEntity $entity) { $repo->delete($this, $entity); if (!$repo->commit()) { $mess = print_r($repo->getErrorEntity()->getErrors()->all(), 1); throw new \RuntimeException("Error delete category news. Error: {$mess}."); } return true; }
/** * Delete all user group member by list * * @param Repository $repo * @param UserGroupMemberEntity[] $entities * @return boolean */ public function deleteAll(Repository $repo, $entities) { foreach ($entities as $entity) { $repo->delete($this, $entity); } if (!$repo->commit()) { $mess = print_r($repo->getErrorEntity()->getErrors()->all(), 1); throw new \RuntimeException("Error delete user group members. Error: {$mess}."); } return true; }
/** * Clear old captcha * @param integer $day * @return boolean * @throws \RuntimeException */ public function clearOld($day) { $repository = new Repository('captcha'); $time = $this->date()->convertTimeStamp(time() - $day * 3600 * 24); $captches = static::finder(CaptchaEntity::getClass())->filter(['<' . CaptchaEntity::C_TIMESTAMP_X => $time])->all(); foreach ($captches as $captcha) { $repository->delete($this, $captcha); } if (!$repository->commit()) { $mess = print_r($repository->getErrorEntity()->getErrors()->all(), 1); throw new \RuntimeException('Error clear old captches. Error:' . $mess); } return true; }
/** * Create captcha * @return \BX\Captcha\Entity\CaptchaEntity * @throws \RuntimeException */ public function create() { $entity = new CaptchaEntity(); $repo = new \BX\DB\UnitOfWork\Repository('captcha'); $repo->add($this, $entity); if (!$repo->commit()) { $mess = print_r($repo->getErrorEntity()->getErrors()->all(), 1); throw new \RuntimeException("Error create captcha. Error: {$mess}."); } return $entity; }
/** * Clear old counter * @param integer $day * @throws \RuntimeException * @return true */ public function clearOld($day = 30) { $time = $this->date()->convertTimeStamp(time() - $day * 3600 * 24); $filter = ['<' . CounterEntity::C_TIMESTAMP_X => $time]; $repo = new Repository('counter'); $counters = self::finder(CounterEntity::getClass())->filter($filter)->all(); foreach ($counters as $counter) { $repo->delete($this, $counter); } if (!$repo->commit()) { $mess = print_r($repo->getErrorEntity()->getErrors()->all(), 1); throw new \RuntimeException('Error delete old counter. Message: ' . $mess); } return true; }
/** * Down command * @return boolean */ public function down() { $this->found = true; $class = $this->package . '\\' . $this->service . '\\Migration'; if (!class_exists($class)) { throw new \LogicException("Class `{$class}` is not found"); } $instanse = new $class(); $trans = new Repository(); foreach ($this->getLastFunctions() as $func) { call_user_func_array([$instanse, $func->function], [false]); $trans->delete($this->table, $func); } if (!$trans->commit(false)) { throw new \RuntimeException('Delete migration error'); } }
/** * Delete news * * @param Repository $repo * @return NewsEntity $entity * @return boolean * @throws \RuntimeException */ public function delete(Repository $repo, NewsEntity $entity) { $repo->delete($this, $entity); $picture = $entity->picture; if (!$repo->commit()) { $mess = print_r($repo->getErrorEntity()->getErrors()->all(), 1); throw new \RuntimeException("Error delete news. Error: {$mess}."); } if ($picture !== null) { $picture->deleteFile(); } return true; }
/** * Delete user * * @param Repository $repo * @param UserEntity $entity * @return boolean * @throws \RuntimeException */ public function delete(Repository $repo, UserEntity $entity) { $repo->delete($this, $entity); if (!$repo->commit()) { throw new ValidateException($repo->getErrorEntity()->getErrors()); } return true; }
/** * Clear olds token * * @param integer $day * @return true * @throws \RuntimeException */ public function clearOld($day) { $time = $this->date()->convertTimeStamp(time() - $day * 3600 * 24); $filter = ['<' . AccessEntity::C_TIMESTAMP_X => $time]; $repo = new Repository($this->repository_name); $entities = self::finder(AccessEntity::getClass())->filter($filter)->all(); foreach ($entities as $entity) { $repo->delete($this, $entity); } if (!$repo->commit()) { $mess = print_r($repo->getErrorEntity()->getErrors()->all(), 1); throw new \RuntimeException("Error delete old access token. Error: {$mess}."); } return true; }