Remove all role-permission relations
mostly used for testing

@param boolean $Ensure
must be set to true or throws an \Exception
@return number of deleted assignments
338338
function resetAssignments($Ensure = false)
	{
		if ($Ensure !== true)
		{
			throw new \Exception ("You must pass true to this function, otherwise it won't work.");
			return;
		}
		$res = Jf::sql ( "DELETE FROM {$this->tablePrefix()}rolepermissions" );

		$Adapter = get_class(Jf::$Db);
		if ($this->isMySql())
			Jf::sql ( "ALTER TABLE {$this->tablePrefix()}rolepermissions AUTO_INCREMENT =1 " );
		elseif ($this->isSQLite())
			Jf::sql ( "delete from sqlite_sequence where name=? ", $this->tablePrefix () . "_rolepermissions" );
		else
			throw new \Exception ( "Rbac can not reset table on this type of database: {$Adapter}" );
		$this->assign ( $this->rootId(), $this->rootId());
		return $res;
	}
425592
public function permissionDelete(Permission $permission)
    {
        if (!$permission->permission_id) {
            throw new ValidationError("Permission is in an invalid state");
        }
        $cur = $this->db->prepare("DELETE FROM auth_permission WHERE permission_id = :pid");
        $cur->bindParam(":pid", $permission->permission_id, PDO::PARAM_INT);
        $this->db->beginTransaction();
        try {
            $cur->execute();
            $this->db->commit();
        } catch (PDOException $db_err) {
            $this->db->rollBack();
            if ($this->logger) {
                $this->logger->error("Failed to delete permission", ['exception' => $db_err]);
            }
            return false;
        }
        return true;
    }
1366104
public function removePermission($permission)
    {
        $permissions = $this->permissions();

        $permissions = array_diff($permissions, [ $permission ]);

        $this->setAttribute('permissions', $permissions);
    }
1261770
public function removeRev($relation)
        {
            if (isset($this->_rev[$relation])) {
                unset($this->_rev[$relation]);
            }

            return $this;
        }
1361048
public function removeDuplicates($strict = false) {
		$field = $strict ? 'message' : 'summary';

		$query = $this->find();
		$options = [
			'fields' => ['type', $field, 'count' => $query->func()->count('*')],
			'conditions' => [],
			'group' => ['type', $field],
			//'having' => $this->alias . '__count > 0',
			//'order' => ['created' => 'DESC']
		];
		$logs = $query->find('all', $options)->disableHydration()->toArray();

		$count = 0;
		foreach ($logs as $key => $log) {
			if ($log['count'] <= 1) {
				continue;
			}
			$options = [
				'fields' => ['id'],
				'keyField' => 'id',
				'valueField' => 'id',
				'conditions' => [
					'type' => $log['type'],
					$field => $log[$field],
				],
				'order' => ['created' => 'DESC']
			];
			$entries = $this->find('list', $options)->toArray();

			// keep the newest entry
			$keep = array_shift($entries);
			if ($entries) {
				$this->deleteAll(['id IN' => $entries]);
			}
			$count += $this->updateAll(['count = count + ' . count($entries)], ['id' => $keep]);
		}

		return $count;
	}
713032
public function delRole($condition)
    {
        $where = [];
        $relationWhere = [];
        if (is_array($condition)) {
            $where[] = ['id', 'IN', $condition];
            $relationWhere[] = ['role_id', 'IN', $condition];
        } else {
            $id = (int)$condition;
            if (is_numeric($id) && $id > 0) {
                $where[] = ['id', '=', $id];
                $relationWhere[] = ['role_id', '=', $condition];
            } else {
                throw new Exception('删除条件错误');
            }
        }
        $this->startTrans();
        if ($this->where($where)->delete() === false) {
            $this->rollback();
            throw new Exception('删除角色出错');
        }
        $rolePermission = new RolePermission($this->connection);
        if ($rolePermission->where($relationWhere)->delete() === false) {
            $this->rollback();
            throw new Exception('删除角色关联权限出错');
        }
        $this->commit();
        return true;
    }
1204017
public function detachPermission($permission)
    {
        if (is_object($permission)) {
            $permission = $permission->getKey();
        }

        if (is_array($permission)) {
            return $this->detachPermissions($permission);
        }

        $this->perms()->detach($permission);
    }
208808
public function delete($table = false)
    {
        if ($table === false) {
            $this->delete = true;
        } else {
            // Reset the array in case the class variable was previously set to a
            // boolean value.
            if (!is_array($this->delete)) {
                $this->delete = array();
            }

            $this->delete[] = $table;
        }

        return $this;
    }
336402
public function checkRole(Model $authority, $roles, $boolean = 'or')
    {
        $count = $this->countMatchingRoles($authority, $roles);

        if ($boolean == 'or') {
            return $count > 0;
        } elseif ($boolean === 'not') {
            return $count === 0;
        }

        return $count == count((array) $roles);
    }
956360
public function detachRole($role, $reload = true)
    {
        event(new DetachingRoleFromPermission($this, $role));
        $results = $this->roles()->detach($role);
        event(new DetachedRoleFromPermission($this, $role, $results));

        $this->loadRoles($reload);

        return $results;
    }
1058456
public function isAllowBulkDelete($allow = null)
    {
        if (null !== $allow) {
            $this->allowBulkDelete = (bool) $allow;
        }

        return $this->allowBulkDelete;
    }
594300
public function clear()
    {
        if (null !== $this->aRole) {
            $this->aRole->removeRolePermission($this);
        }
        if (null !== $this->aPermission) {
            $this->aPermission->removeRolePermission($this);
        }
        $this->role_id = null;
        $this->permission_id = null;
        $this->alreadyInSave = false;
        $this->clearAllReferences();
        $this->resetModified();
        $this->setNew(true);
        $this->setDeleted(false);
    }
626173
public function deleteCondition()
    {
        if (null === $this->delete_condition || false === $this->delete_condition) {
            return false;
        }

        return $this->delete_condition;
    }
396954
public function revokePermission($permission)
    {
        return $this->mapArray($permission, function ($permission) {

            $permissionId = $this->parsePermissionId($permission);

            return $this->permissions()->detach($permissionId);
        });
    }
1167854
public function deletePermission($permission)
    {
        if ($this->hasPermission($permission)) {
            return PermissionRole::where(
                    ['role_id' => $this->id, 'permission_id' => $permission->id]
                )->first()->delete();
        }

        return false;
    }
1313609
public function delete($source=null) {
        global $USER, $CFG, $DB;

        if (empty($this->id)) {
            debugging('Can not delete grade object, no id!');
            return false;
        }

        $data = $this->get_record_data();

        if ($DB->delete_records($this->table, array('id'=>$this->id))) {
            if (empty($CFG->disablegradehistory)) {
                unset($data->id);
                unset($data->timecreated);
                $data->action       = GRADE_HISTORY_DELETE;
                $data->oldid        = $this->id;
                $data->source       = $source;
                $data->timemodified = time();
                $data->loggeduser   = $USER->id;
                $DB->insert_record($this->table.'_history', $data);
            }

            $this->notify_changed(true);

            $this->delete_feedback_files();

            return true;
        } else {
            return false;
        }
    }
1307899
function remove($ID, $Recursive = false)
	{
		$this->unassignRoles ( $ID );
		if (! $Recursive)
			return $this->permissions->deleteConditional ( "ID=?", $ID );
		else
			return $this->permissions->deleteSubtreeConditional ( "ID=?", $ID );
	}