Esempio n. 1
0
 protected function validate(Errors $errors)
 {
     $nid = $this->key;
     $count = $this->module->model->filter_by_parentid($nid)->count;
     if ($count) {
         $errors[] = $errors->format('This page has :count direct children.', array(':count' => $count));
     }
     $count = $this->module->model->filter_by_locationid($nid)->count;
     if ($count) {
         $errors[] = $errors->format('This page is used in :count redirections.', array(':count' => $count));
     }
     return parent::validate($errors);
 }
Esempio n. 2
0
 protected function validate(Errors $errors)
 {
     $post_id = $this->request['post_id'];
     if (!$post_id) {
         $errors['post_id'] = $errors->format("PostID is required.");
     } else {
         $post = $this->app->models['posts'][$post_id];
     }
     return $errors;
 }
Esempio n. 3
0
 protected function validate(\ICanboogie\Errors $errors)
 {
     $order = $this->request['order'];
     $relation = $this->request['relation'];
     if ($order && $relation) {
         foreach ($order as $nid) {
             if (!isset($relation[$nid])) {
                 $errors['relation'] = $errors->format("Missing relation for nid %nid.", array('nid' => $nid));
             }
         }
     } else {
         if (!$order) {
             $errors['order'] = $errors->format("The %param param is required", array('param' => 'order'));
         }
         if (!$relation) {
             $errors['relation'] = $errors->format("The %param param is required", array('param' => 'relation'));
         }
     }
     return !$errors->count();
 }
Esempio n. 4
0
 /**
  * For each defined content we check that the corresponding editor is also defined.
  */
 protected function validate(\ICanBoogie\Errors $errors)
 {
     $contents = $this->request['contents'];
     $editors = $this->request['editors'];
     if ($contents) {
         foreach (array_keys($contents) as $name) {
             if (!array_key_exists($name, $editors)) {
                 $errors['content'][] = $errors->format('The editor is missing for the content %name.', array('name' => $name));
             }
         }
     }
     return parent::validate($errors);
 }
Esempio n. 5
0
 /**
  * Only modules which are not used by other modules can be disabled.
  */
 protected function validate(\ICanboogie\Errors $errors)
 {
     global $core;
     if ($this->key) {
         foreach (array_keys($this->key) as $module_id) {
             $n = $core->modules->usage($module_id);
             if ($n) {
                 $errors[] = $errors->format('The module %title cannot be disabled, :count modules are using it.', array('title' => I18n\t($module_id, array(), array('scope' => 'module_title')), ':count' => $n));
             }
         }
     }
     return $errors;
 }
Esempio n. 6
0
 protected function validate(Errors $errors)
 {
     $request = $this->request;
     $username = $request['username'];
     $password = $request['password'];
     $user = $this->module->model->filter_by_username($username)->one;
     if (!$user || !$user->verify_password($password)) {
         $errors['username'] = $errors->format("Unknown username/password combination");
         $errors['password'] = true;
         return false;
     }
     $this->user = $this->module->model[$user->id];
     return true;
 }
Esempio n. 7
0
 /**
  * Install the module.
  *
  * If the module has models they are installed.
  *
  * @param Errors $errors Error collection.
  *
  * @return boolean|null true if the module has successfully been installed, false if the
  * module (or parts of the module) fails to install or null if the module has
  * no installation process.
  */
 public function install(Errors $errors)
 {
     if (empty($this->descriptor[Descriptor::MODELS])) {
         return null;
     }
     $rc = true;
     foreach ($this->descriptor[Descriptor::MODELS] as $name => $tags) {
         $model = $this->model($name);
         if ($model->is_installed()) {
             continue;
         }
         try {
             $model->install();
         } catch (\Exception $e) {
             $errors[$this->id] = $errors->format('Unable to install model %model: !message', ['model' => $name, 'message' => $e->getMessage()]);
             $rc = false;
         }
     }
     return $rc;
 }