<commit_before><?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Migration_Permissions_to_manage_role_permissions extends Migration {
	
	public function up() 
	{
		$prefix = $this->db->dbprefix;
		
		// name field in permissions table is too short bump it up to 50
		$sql = "ALTER TABLE `{$prefix}permissions` CHANGE `name` `name` VARCHAR(50) NULL";
		$this->db->query($sql);	
		
		$roles = $this->role_model->find_all();
		if (isset($roles) && is_array($roles) && count($roles)) {
			foreach ($roles as $role) {
				// add the permission
				$this->db->query("INSERT INTO {$prefix}permissions(name, description) VALUES('Permissions.".$role->role_name.".Manage','To manage the access control permissions for the ".$role->role_name." role.')");
				// give administrators full right to manage permissions
				$this->db->query("INSERT INTO {$prefix}role_permissions VALUES(1,".$this->db->insert_id().")");
			}
		}		
	}
	
	//--------------------------------------------------------------------
	
	public function down() 
	{
		$prefix = $this->db->dbprefix;
		
		$roles = $this->role_model->find_all();
		if (isset($roles) && is_array($roles) && count($roles)) {
			foreach ($roles as $role) {
				// delete any but that has any of these permissions from the role_permissions table
				$query = $this->db->query("SELECT permission_id FROM {$prefix}permissions WHERE name = 'Permissions.".$role->role_name.".Manage'");<commit_msg>Changed the migration to assign permission to current_role_id or administrators on fresh install.<commit_after><?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Migration_Permissions_to_manage_role_permissions extends Migration {
	
	public function up() 
	{
		$prefix = $this->db->dbprefix;
		
		// name field in permissions table is too short bump it up to 50
		$sql = "ALTER TABLE `{$prefix}permissions` CHANGE `name` `name` VARCHAR(50) NULL";
		$this->db->query($sql);	
		
		$roles = $this->role_model->find_all();
		if (isset($roles) && is_array($roles) && count($roles)) {
			foreach ($roles as $role) {
				// add the permission
				$this->db->query("INSERT INTO {$prefix}permissions(name, description) VALUES('Permissions.".$role->role_name.".Manage','To manage the access control permissions for the ".$role->role_name." role.')");
				// give current role (or administrators if fresh install) full right to manage permissions
				$assign_role = ($this->session->userdata('role_id') ? $this->session->userdata('role_id') : 1;
				$this->db->query("INSERT INTO {$prefix}role_permissions VALUES(".$assign_role.",".$this->db->insert_id().")");
			}
		}		
	}
	
	//--------------------------------------------------------------------
	
	public function down() 
	{
		$prefix = $this->db->dbprefix;
		
		$roles = $this->role_model->find_all();
		if (isset($roles) && is_array($roles) && count($roles)) {
			foreach ($roles as $role) {
				// delete any but that has any of these permissions from the role_permissions table
				$query = $this->db->query("SELECT permission_id FROM {$prefix}permissions WHERE name = 'Permissions.".$role->role_name.".Manage'");
{'fraction_non_alphanumeric': 0.20222575516693164, 'fraction_numerical': 0.003179650238473768, 'mean_word_length': 3.5007153075822606, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2281087', 'n_tokens_mistral': 1051, 'n_tokens_neox': 922, 'n_words': 249}