Scalr\Model\Entity\Role::setScripts PHP Méthode

setScripts() public méthode

Set scripts of the Role TODO refactor this method to new Entities
public setScripts ( array $scripts )
$scripts array
    public function setScripts($scripts)
    {
        if (!$this->id) {
            return;
        }
        if (!is_array($scripts)) {
            return;
        }
        $ids = array();
        foreach ($scripts as $script) {
            // TODO: check permission for script_id
            if (!$script['role_script_id']) {
                $this->db()->Execute('INSERT INTO role_scripts SET
                    `role_id` = ?,
                    `event_name` = ?,
                    `target` = ?,
                    `script_id` = ?,
                    `version` = ?,
                    `timeout` = ?,
                    `issync` = ?,
                    `params` = ?,
                    `order_index` = ?,
                    `hash` = ?,
                    `script_path` = ?,
                    `run_as` = ?,
                    `script_type` = ?
                ', array($this->id, $script['event_name'], $script['target'], $script['script_id'] != 0 ? $script['script_id'] : NULL, $script['version'], $script['timeout'], $script['isSync'], serialize($script['params']), $script['order_index'], !$script['hash'] ? CryptoTool::sault(12) : $script['hash'], $script['script_path'], $script['run_as'], $script['script_type']));
                $ids[] = $this->db()->Insert_ID();
            } else {
                $this->db()->Execute('UPDATE role_scripts SET
                    `event_name` = ?,
                    `target` = ?,
                    `script_id` = ?,
                    `version` = ?,
                    `timeout` = ?,
                    `issync` = ?,
                    `params` = ?,
                    `order_index` = ?,
                    `script_path` = ?,
                    `run_as` = ?,
                    `script_type` = ?
                    WHERE id = ? AND role_id = ?
                ', array($script['event_name'], $script['target'], $script['script_id'] != 0 ? $script['script_id'] : NULL, $script['version'], $script['timeout'], $script['isSync'], serialize($script['params']), $script['order_index'], $script['script_path'], $script['run_as'], $script['script_type'], $script['role_script_id'], $this->id));
                $ids[] = $script['role_script_id'];
            }
        }
        $toRemove = $this->db()->Execute('SELECT id, hash FROM role_scripts WHERE role_id = ? AND id NOT IN (\'' . implode("','", $ids) . '\')', array($this->id));
        while ($rScript = $toRemove->FetchRow()) {
            $this->db()->Execute("DELETE FROM farm_role_scripting_params WHERE hash = ? AND farm_role_id IN (SELECT id FROM farm_roles WHERE role_id = ?)", array($rScript['hash'], $this->id));
            $this->db()->Execute("DELETE FROM role_scripts WHERE id = ?", array($rScript['id']));
        }
    }