Example #1
0
 /**
  * Makes sure the node to delete is not used as a native target by other nodes.
  *
  * @throws Exception if the node to delete is the native target of another node.
  */
 public function delete($key)
 {
     $native_refs = $this->select('nid')->filter_by_nativeid($key)->all(\PDO::FETCH_COLUMN);
     if ($native_refs) {
         throw new Exception('Node record cannot be deleted because it is used as native source by the following records: \\1', array(implode(', ', $native_refs)));
     }
     return parent::delete($key);
 }
Example #2
0
 public function save(array $properties, $key = null, array $options = [])
 {
     global $core;
     if (!$key && empty($properties[User::PASSWORD])) {
         $properties[User::PASSWORD] = md5(uniqid());
     }
     #
     # If defined, the password is encrypted before we pass it to our super class.
     #
     unset($properties[User::PASSWORD_HASH]);
     if (!empty($properties[User::PASSWORD])) {
         $properties[User::PASSWORD_HASH] = User::hash_password($properties[User::PASSWORD]);
     }
     $rc = parent::save($properties, $key, $options);
     #
     # roles
     #
     if (isset($properties[User::ROLES])) {
         $has_many_roles = $core->models['users/has_many_roles'];
         if ($key) {
             $has_many_roles->filter_by_uid($key)->delete();
         }
         foreach ($properties[User::ROLES] as $rid) {
             if ($rid == 2) {
                 continue;
             }
             $has_many_roles->execute('INSERT {self} SET uid = ?, rid = ?', [$rc, $rid]);
         }
     }
     #
     # sites
     #
     if (isset($properties[User::RESTRICTED_SITES])) {
         $has_many_sites = $core->models['users/has_many_sites'];
         if ($key) {
             $has_many_sites->filter_by_uid($key)->delete();
         }
         foreach ($properties[User::RESTRICTED_SITES] as $siteid) {
             $has_many_sites->execute('INSERT {self} SET uid = ?, siteid = ?', [$rc, $siteid]);
         }
     }
     return $rc;
 }