Class lispa\amos\core\migration\AmosMigration

Inheritancelispa\amos\core\migration\AmosMigration » yii\db\Migration » yii\base\Component » yii\base\Object
Implementsyii\base\Configurable, yii\db\MigrationInterface
Uses Traitsyii\db\SchemaBuilderTrait
Deprecated since version Don't use this class. Not removed only for retro compatibility.

Class AmosMigration

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$behaviors yii\base\Behavior[] List of behaviors attached to this component yii\base\Component
$db yii\db\Connection|array|string The DB connection object or the application component ID of the DB connection that this migration should work with. yii\db\Migration

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$authorizations array An array where you can insert permissions and roles that will be inserted in the database. lispa\amos\core\migration\AmosMigration

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\Component
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\Object
__get() Returns the value of a component property. yii\base\Component
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Component
__set() Sets the value of a component property. yii\base\Component
__unset() Sets a component property to be null. yii\base\Component
addAuthorizations() This is the method that parse all the authorizations array and add them to the system. It checks the data integrity and add permissions, roles and associations between them. lispa\amos\core\migration\AmosMigration
addColumn() Builds and executes a SQL statement for adding a new DB column. yii\db\Migration
addCommentOnColumn() Builds and execute a SQL statement for adding comment to column yii\db\Migration
addCommentOnTable() Builds a SQL statement for adding comment to table yii\db\Migration
addForeignKey() Builds a SQL statement for adding a foreign key constraint to an existing table. yii\db\Migration
addPrimaryKey() Builds and executes a SQL statement for creating a primary key. yii\db\Migration
alterColumn() Builds and executes a SQL statement for changing the definition of a column. yii\db\Migration
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
batchInsert() Creates and executes an batch INSERT SQL statement. yii\db\Migration
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
bigInteger() Creates a bigint column. yii\db\SchemaBuilderTrait
bigPrimaryKey() Creates a big primary key column. yii\db\SchemaBuilderTrait
binary() Creates a binary column. yii\db\SchemaBuilderTrait
boolean() Creates a boolean column. yii\db\SchemaBuilderTrait
canGetProperty() Returns a value indicating whether a property can be read. yii\base\Component
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Component
char() Creates a char column. yii\db\SchemaBuilderTrait
className() Returns the fully qualified name of this class. yii\base\Object
createIndex() Builds and executes a SQL statement for creating a new index. yii\db\Migration
createTable() Builds and executes a SQL statement for creating a new DB table. yii\db\Migration
date() Creates a date column. yii\db\SchemaBuilderTrait
dateTime() Creates a datetime column. yii\db\SchemaBuilderTrait
decimal() Creates a decimal column. yii\db\SchemaBuilderTrait
delete() Creates and executes a DELETE SQL statement. yii\db\Migration
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
double() Creates a double column. yii\db\SchemaBuilderTrait
down() This method contains the logic to be executed when removing this migration. yii\db\Migration
dropColumn() Builds and executes a SQL statement for dropping a DB column. yii\db\Migration
dropCommentFromColumn() Builds and execute a SQL statement for dropping comment from column yii\db\Migration
dropCommentFromTable() Builds a SQL statement for dropping comment from table yii\db\Migration
dropForeignKey() Builds a SQL statement for dropping a foreign key constraint. yii\db\Migration
dropIndex() Builds and executes a SQL statement for dropping an index. yii\db\Migration
dropPrimaryKey() Builds and executes a SQL statement for dropping a primary key. yii\db\Migration
dropTable() Builds and executes a SQL statement for dropping a DB table. yii\db\Migration
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
execute() Executes a SQL statement. yii\db\Migration
float() Creates a float column. yii\db\SchemaBuilderTrait
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\Component
hasProperty() Returns a value indicating whether a property is defined for this component. yii\base\Component
init() lispa\amos\core\migration\AmosMigration
insert() Creates and executes an INSERT SQL statement. yii\db\Migration
integer() Creates an integer column. yii\db\SchemaBuilderTrait
money() Creates a money column. yii\db\SchemaBuilderTrait
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
primaryKey() Creates a primary key column. yii\db\SchemaBuilderTrait
removeAuthorizations() This is the method that parse all the authorizations array and remove them from the system. It checks the data integrity and add permissions, roles and associations between them. lispa\amos\core\migration\AmosMigration
renameColumn() Builds and executes a SQL statement for renaming a column. yii\db\Migration
renameTable() Builds and executes a SQL statement for renaming a DB table. yii\db\Migration
safeDown() This method contains the logic to be executed when removing this migration. yii\db\Migration
safeUp() This method contains the logic to be executed when applying this migration. yii\db\Migration
smallInteger() Creates a smallint column. yii\db\SchemaBuilderTrait
string() Creates a string column. yii\db\SchemaBuilderTrait
text() Creates a text column. yii\db\SchemaBuilderTrait
time() Creates a time column. yii\db\SchemaBuilderTrait
timestamp() Creates a timestamp column. yii\db\SchemaBuilderTrait
trigger() Triggers an event. yii\base\Component
truncateTable() Builds and executes a SQL statement for truncating a DB table. yii\db\Migration
up() This method contains the logic to be executed when applying this migration. yii\db\Migration
update() Creates and executes an UPDATE SQL statement. yii\db\Migration

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
addItemChilds() This method creates the associations between permissions and roles. lispa\amos\core\migration\AmosMigration
addPermissionsAndRoles() Method that insert all permissions and roles in the authorizations array. lispa\amos\core\migration\AmosMigration
checkArrayStructure() Method to check the authorizations array data integrity. It checks if there's any missing field or if a field does not contain the right value type. lispa\amos\core\migration\AmosMigration
checkFieldType() Method that checks the correct type of a field value. lispa\amos\core\migration\AmosMigration
createPermission() Method that insert a single permission in the system. It print a message if permission exists or permission is successfully created or an error occurred. lispa\amos\core\migration\AmosMigration
createRole() Method that insert a single role in the system. It print a message if role exists or role is successfully created or an error occurred. lispa\amos\core\migration\AmosMigration
createRule() Method that create a rule in the system. It print a message if permission exists or permission is successfully created or an error occurred. lispa\amos\core\migration\AmosMigration
deletePermission() Method that delete a single permission from the system. It print a message if permission does not exist or permission is successfully deleted or an error occurred. lispa\amos\core\migration\AmosMigration
deleteRole() Method that insert a single role in the system. It print a message if role exists or role is successfully created or an error occurred. lispa\amos\core\migration\AmosMigration
getDb() yii\db\SchemaBuilderTrait
removeItemChilds() This method destroy the associations between permissions and roles. lispa\amos\core\migration\AmosMigration
removePermissionsAndRoles() Method that delete all permissions and roles in the authorizations array. lispa\amos\core\migration\AmosMigration
setAuthorizations() Set your new authorizations here. You can see a configurations array example below. lispa\amos\core\migration\AmosMigration

Property Details

$authorizations protected property

An array where you can insert permissions and roles that will be inserted in the database.

protected array $authorizations null

Method Details

addAuthorizations() public method

This is the method that parse all the authorizations array and add them to the system. It checks the data integrity and add permissions, roles and associations between them.

public boolean addAuthorizations ( )
return boolean

Returns true if everything goes well. False otherwise.

addItemChilds() protected method

This method creates the associations between permissions and roles.

protected boolean addItemChilds ( )
return boolean

Returns true if everything goes well. False otherwise.

addPermissionsAndRoles() protected method

Method that insert all permissions and roles in the authorizations array.

protected boolean addPermissionsAndRoles ( )
return boolean

Returns true if everything goes well. False otherwise.

checkArrayStructure() protected method

Method to check the authorizations array data integrity. It checks if there's any missing field or if a field does not contain the right value type.

protected boolean checkArrayStructure ( )
return boolean

Returns true if everything goes well. False otherwise.

checkFieldType() protected method

Method that checks the correct type of a field value.

protected boolean checkFieldType ( $fieldName, $fieldType, $authorization )
$fieldName string

Name of an internal array field.

$fieldType string

Value type of an internal array field.

$authorization array

One internal array.

return boolean

Returns true if everything goes well. False otherwise.

createPermission() protected method

Method that insert a single permission in the system. It print a message if permission exists or permission is successfully created or an error occurred.

protected boolean createPermission ( $authorization )
$authorization array

One internal array.

return boolean

Returns true if everything goes well. False otherwise.

createRole() protected method

Method that insert a single role in the system. It print a message if role exists or role is successfully created or an error occurred.

protected boolean createRole ( $authorization )
$authorization array

One internal array.

return boolean

Returns true if everything goes well. False otherwise.

createRule() protected method

Method that create a rule in the system. It print a message if permission exists or permission is successfully created or an error occurred.

protected null|string createRule ( $authorization )
$authorization array

One internal array.

return null|string

Returns rule name if succesfully created or exists. Null otherwise.

deletePermission() protected method

Method that delete a single permission from the system. It print a message if permission does not exist or permission is successfully deleted or an error occurred.

protected boolean deletePermission ( $authorization )
$authorization array

One internal array.

return boolean

Returns true if everything goes well. False otherwise.

deleteRole() protected method

Method that insert a single role in the system. It print a message if role exists or role is successfully created or an error occurred.

protected boolean deleteRole ( $authorization )
$authorization array

One internal array.

return boolean

Returns true if everything goes well. False otherwise.

init() public method

See also yii\db\Migration::init() for more info.

public void init ( )
removeAuthorizations() public method

This is the method that parse all the authorizations array and remove them from the system. It checks the data integrity and add permissions, roles and associations between them.

public boolean removeAuthorizations ( )
return boolean

Returns true if everything goes well. False otherwise.

removeItemChilds() protected method

This method destroy the associations between permissions and roles.

protected boolean removeItemChilds ( )
return boolean

Returns true if everything goes well. False otherwise.

removePermissionsAndRoles() protected method

Method that delete all permissions and roles in the authorizations array.

protected boolean removePermissionsAndRoles ( )
return boolean

Returns true if everything goes well. False otherwise.

setAuthorizations() protected method

Set your new authorizations here. You can see a configurations array example below.

$this->authorizations = [

  [
      'name' => 'ROLE_ONE',
      'type' => Permission::TYPE_ROLE,
      'description' => 'Role description',
      'ruleName' => null,     // This is a string
  ],
  [
      'name' => 'ROLE_TWO',
      'type' => Permission::TYPE_ROLE,
      'description' => 'Role description',
      'ruleName' => null,     // This is a string
      'parent' => ['ROLE_ONE']
  ],
  [
      'name' => 'PERMISSION_NAME',
      'type' => Permission::TYPE_PERMISSION,
      'description' => 'Permission description',
      'ruleName' => null,     // This is a string
      'parent' => ['ROLE_ONE']
  ],
  [
      'name' => 'PERMISSION_NAME',
      'type' => Permission::TYPE_PERMISSION,
      'description' => 'Permission description',
      'ruleName' => null,     // This is a string
      'parent' => ['ROLE_ONE', 'ROLE_TWO', ...]
  ],
  .
  .
  .
  ];
protected void setAuthorizations ( )