@@ -10,35 +10,35 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class Migration_create_settings_table extends CI_Migration { |
| 12 | 12 | |
| 13 | - public function up () |
|
| 14 | - { |
|
| 15 | - $fields = [ |
|
| 16 | - 'name' => [ |
|
| 17 | - 'type' => 'varchar', |
|
| 18 | - 'constraint' => 255 |
|
| 19 | - ], |
|
| 20 | - 'value' => [ |
|
| 21 | - 'type' => 'varchar', |
|
| 22 | - 'constraint' => 255, |
|
| 23 | - 'null' => true |
|
| 24 | - ], |
|
| 25 | - 'group' => [ |
|
| 26 | - 'type' => 'varchar', |
|
| 27 | - 'constraint' => 255 |
|
| 28 | - ] |
|
| 29 | - ]; |
|
| 30 | - $this->dbforge->add_field($fields); |
|
| 31 | - $this->dbforge->add_key(['name', 'group'], true); |
|
| 32 | - $this->dbforge->create_table('settings', true, config_item('migration_create_table_attr')); |
|
| 33 | - } |
|
| 13 | + public function up () |
|
| 14 | + { |
|
| 15 | + $fields = [ |
|
| 16 | + 'name' => [ |
|
| 17 | + 'type' => 'varchar', |
|
| 18 | + 'constraint' => 255 |
|
| 19 | + ], |
|
| 20 | + 'value' => [ |
|
| 21 | + 'type' => 'varchar', |
|
| 22 | + 'constraint' => 255, |
|
| 23 | + 'null' => true |
|
| 24 | + ], |
|
| 25 | + 'group' => [ |
|
| 26 | + 'type' => 'varchar', |
|
| 27 | + 'constraint' => 255 |
|
| 28 | + ] |
|
| 29 | + ]; |
|
| 30 | + $this->dbforge->add_field($fields); |
|
| 31 | + $this->dbforge->add_key(['name', 'group'], true); |
|
| 32 | + $this->dbforge->create_table('settings', true, config_item('migration_create_table_attr')); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - //-------------------------------------------------------------------- |
|
| 35 | + //-------------------------------------------------------------------- |
|
| 36 | 36 | |
| 37 | - public function down () |
|
| 38 | - { |
|
| 39 | - $this->dbforge->drop_table('settings'); |
|
| 40 | - } |
|
| 37 | + public function down () |
|
| 38 | + { |
|
| 39 | + $this->dbforge->drop_table('settings'); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - //-------------------------------------------------------------------- |
|
| 42 | + //-------------------------------------------------------------------- |
|
| 43 | 43 | |
| 44 | 44 | } |
@@ -10,52 +10,52 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class Migration_create_mail_queue extends CI_Migration { |
| 12 | 12 | |
| 13 | - public function up () |
|
| 14 | - { |
|
| 15 | - $fields = [ |
|
| 16 | - 'id' => [ |
|
| 17 | - 'type' => 'int', |
|
| 18 | - 'constraint' => 11, |
|
| 19 | - 'unsigned' => true, |
|
| 20 | - 'auto_increment' => true |
|
| 21 | - ], |
|
| 22 | - 'mailer' => [ |
|
| 23 | - 'type' => 'varchar', |
|
| 24 | - 'constraint' => 255 |
|
| 25 | - ], |
|
| 26 | - 'params' => [ |
|
| 27 | - 'type' => 'text', |
|
| 28 | - 'null' => true |
|
| 29 | - ], |
|
| 30 | - 'options' => [ |
|
| 31 | - 'type' => 'text', |
|
| 32 | - 'null' => true |
|
| 33 | - ], |
|
| 34 | - 'sent' => [ |
|
| 35 | - 'type' => 'tinyint', |
|
| 36 | - 'constraint' => 1, |
|
| 37 | - 'default' => 0 |
|
| 38 | - ], |
|
| 39 | - 'sent_on' => [ |
|
| 40 | - 'type' => 'datetime', |
|
| 41 | - 'null' => true, |
|
| 42 | - 'default' => null |
|
| 43 | - ], |
|
| 44 | - ]; |
|
| 13 | + public function up () |
|
| 14 | + { |
|
| 15 | + $fields = [ |
|
| 16 | + 'id' => [ |
|
| 17 | + 'type' => 'int', |
|
| 18 | + 'constraint' => 11, |
|
| 19 | + 'unsigned' => true, |
|
| 20 | + 'auto_increment' => true |
|
| 21 | + ], |
|
| 22 | + 'mailer' => [ |
|
| 23 | + 'type' => 'varchar', |
|
| 24 | + 'constraint' => 255 |
|
| 25 | + ], |
|
| 26 | + 'params' => [ |
|
| 27 | + 'type' => 'text', |
|
| 28 | + 'null' => true |
|
| 29 | + ], |
|
| 30 | + 'options' => [ |
|
| 31 | + 'type' => 'text', |
|
| 32 | + 'null' => true |
|
| 33 | + ], |
|
| 34 | + 'sent' => [ |
|
| 35 | + 'type' => 'tinyint', |
|
| 36 | + 'constraint' => 1, |
|
| 37 | + 'default' => 0 |
|
| 38 | + ], |
|
| 39 | + 'sent_on' => [ |
|
| 40 | + 'type' => 'datetime', |
|
| 41 | + 'null' => true, |
|
| 42 | + 'default' => null |
|
| 43 | + ], |
|
| 44 | + ]; |
|
| 45 | 45 | |
| 46 | - $this->dbforge->add_field($fields); |
|
| 47 | - $this->dbforge->add_key('id', true); |
|
| 48 | - $this->dbforge->add_key('sent'); |
|
| 49 | - $this->dbforge->create_table('mail_queue', true, config_item('migration_create_table_attr')); |
|
| 50 | - } |
|
| 46 | + $this->dbforge->add_field($fields); |
|
| 47 | + $this->dbforge->add_key('id', true); |
|
| 48 | + $this->dbforge->add_key('sent'); |
|
| 49 | + $this->dbforge->create_table('mail_queue', true, config_item('migration_create_table_attr')); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - //-------------------------------------------------------------------- |
|
| 52 | + //-------------------------------------------------------------------- |
|
| 53 | 53 | |
| 54 | - public function down () |
|
| 55 | - { |
|
| 56 | - $this->dbforge->drop_table('mail_queue'); |
|
| 57 | - } |
|
| 54 | + public function down () |
|
| 55 | + { |
|
| 56 | + $this->dbforge->drop_table('mail_queue'); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - //-------------------------------------------------------------------- |
|
| 59 | + //-------------------------------------------------------------------- |
|
| 60 | 60 | |
| 61 | 61 | } |
@@ -10,110 +10,110 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class Migration_create_authorization_tables extends CI_Migration { |
| 12 | 12 | |
| 13 | - public function up () |
|
| 14 | - { |
|
| 13 | + public function up () |
|
| 14 | + { |
|
| 15 | 15 | /** |
| 16 | 16 | * Groups Table |
| 17 | 17 | */ |
| 18 | - $fields = [ |
|
| 19 | - 'id' => [ |
|
| 20 | - 'type' => 'int', |
|
| 21 | - 'constraint' => 11, |
|
| 22 | - 'unsigned' => true, |
|
| 23 | - 'auto_increment' => true |
|
| 24 | - ], |
|
| 25 | - 'name' => [ |
|
| 26 | - 'type' => 'varchar', |
|
| 27 | - 'constraint' => 255 |
|
| 28 | - ], |
|
| 29 | - 'description' => [ |
|
| 30 | - 'type' => 'varchar', |
|
| 31 | - 'constraint' => 255 |
|
| 32 | - ] |
|
| 33 | - ]; |
|
| 18 | + $fields = [ |
|
| 19 | + 'id' => [ |
|
| 20 | + 'type' => 'int', |
|
| 21 | + 'constraint' => 11, |
|
| 22 | + 'unsigned' => true, |
|
| 23 | + 'auto_increment' => true |
|
| 24 | + ], |
|
| 25 | + 'name' => [ |
|
| 26 | + 'type' => 'varchar', |
|
| 27 | + 'constraint' => 255 |
|
| 28 | + ], |
|
| 29 | + 'description' => [ |
|
| 30 | + 'type' => 'varchar', |
|
| 31 | + 'constraint' => 255 |
|
| 32 | + ] |
|
| 33 | + ]; |
|
| 34 | 34 | |
| 35 | - $this->dbforge->add_field($fields); |
|
| 36 | - $this->dbforge->add_key('id', true); |
|
| 37 | - $this->dbforge->create_table('auth_groups', true, config_item('migration_create_table_attr')); |
|
| 38 | - /** |
|
| 39 | - * Permissions Table |
|
| 40 | - */ |
|
| 41 | - $fields = [ |
|
| 42 | - 'id' => [ |
|
| 43 | - 'type' => 'int', |
|
| 44 | - 'constraint' => 11, |
|
| 45 | - 'unsigned' => true, |
|
| 46 | - 'auto_increment' => true |
|
| 47 | - ], |
|
| 48 | - 'name' => [ |
|
| 49 | - 'type' => 'varchar', |
|
| 50 | - 'constraint' => 255 |
|
| 51 | - ], |
|
| 52 | - 'description' => [ |
|
| 53 | - 'type' => 'varchar', |
|
| 54 | - 'constraint' => 255 |
|
| 55 | - ] |
|
| 56 | - ]; |
|
| 35 | + $this->dbforge->add_field($fields); |
|
| 36 | + $this->dbforge->add_key('id', true); |
|
| 37 | + $this->dbforge->create_table('auth_groups', true, config_item('migration_create_table_attr')); |
|
| 38 | + /** |
|
| 39 | + * Permissions Table |
|
| 40 | + */ |
|
| 41 | + $fields = [ |
|
| 42 | + 'id' => [ |
|
| 43 | + 'type' => 'int', |
|
| 44 | + 'constraint' => 11, |
|
| 45 | + 'unsigned' => true, |
|
| 46 | + 'auto_increment' => true |
|
| 47 | + ], |
|
| 48 | + 'name' => [ |
|
| 49 | + 'type' => 'varchar', |
|
| 50 | + 'constraint' => 255 |
|
| 51 | + ], |
|
| 52 | + 'description' => [ |
|
| 53 | + 'type' => 'varchar', |
|
| 54 | + 'constraint' => 255 |
|
| 55 | + ] |
|
| 56 | + ]; |
|
| 57 | 57 | |
| 58 | - $this->dbforge->add_field($fields); |
|
| 59 | - $this->dbforge->add_key('id', true); |
|
| 60 | - $this->dbforge->create_table('auth_permissions', true, config_item('migration_create_table_attr')); |
|
| 58 | + $this->dbforge->add_field($fields); |
|
| 59 | + $this->dbforge->add_key('id', true); |
|
| 60 | + $this->dbforge->create_table('auth_permissions', true, config_item('migration_create_table_attr')); |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Groups/Permissions Table |
|
| 64 | - */ |
|
| 65 | - $fields = [ |
|
| 66 | - 'group_id' => [ |
|
| 67 | - 'type' => 'int', |
|
| 68 | - 'constraint' => 11, |
|
| 69 | - 'unsigned' => true, |
|
| 70 | - 'default' => 0 |
|
| 71 | - ], |
|
| 72 | - 'permission_id' => [ |
|
| 73 | - 'type' => 'int', |
|
| 74 | - 'constraint' => 11, |
|
| 75 | - 'unsigned' => true, |
|
| 76 | - 'default' => 0 |
|
| 77 | - ], |
|
| 78 | - ]; |
|
| 62 | + /** |
|
| 63 | + * Groups/Permissions Table |
|
| 64 | + */ |
|
| 65 | + $fields = [ |
|
| 66 | + 'group_id' => [ |
|
| 67 | + 'type' => 'int', |
|
| 68 | + 'constraint' => 11, |
|
| 69 | + 'unsigned' => true, |
|
| 70 | + 'default' => 0 |
|
| 71 | + ], |
|
| 72 | + 'permission_id' => [ |
|
| 73 | + 'type' => 'int', |
|
| 74 | + 'constraint' => 11, |
|
| 75 | + 'unsigned' => true, |
|
| 76 | + 'default' => 0 |
|
| 77 | + ], |
|
| 78 | + ]; |
|
| 79 | 79 | |
| 80 | - $this->dbforge->add_field($fields); |
|
| 81 | - $this->dbforge->add_key(['group_id', 'permission_id']); |
|
| 82 | - $this->dbforge->create_table('auth_groups_permissions', true, config_item('migration_create_table_attr')); |
|
| 80 | + $this->dbforge->add_field($fields); |
|
| 81 | + $this->dbforge->add_key(['group_id', 'permission_id']); |
|
| 82 | + $this->dbforge->create_table('auth_groups_permissions', true, config_item('migration_create_table_attr')); |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Users/Groups Table |
|
| 86 | - */ |
|
| 87 | - $fields = [ |
|
| 88 | - 'group_id' => [ |
|
| 89 | - 'type' => 'int', |
|
| 90 | - 'constraint' => 11, |
|
| 91 | - 'unsigned' => true, |
|
| 92 | - 'default' => 0 |
|
| 93 | - ], |
|
| 94 | - 'user_id' => [ |
|
| 95 | - 'type' => 'int', |
|
| 96 | - 'constraint' => 11, |
|
| 97 | - 'unsigned' => true, |
|
| 98 | - 'default' => 0 |
|
| 99 | - ], |
|
| 100 | - ]; |
|
| 84 | + /** |
|
| 85 | + * Users/Groups Table |
|
| 86 | + */ |
|
| 87 | + $fields = [ |
|
| 88 | + 'group_id' => [ |
|
| 89 | + 'type' => 'int', |
|
| 90 | + 'constraint' => 11, |
|
| 91 | + 'unsigned' => true, |
|
| 92 | + 'default' => 0 |
|
| 93 | + ], |
|
| 94 | + 'user_id' => [ |
|
| 95 | + 'type' => 'int', |
|
| 96 | + 'constraint' => 11, |
|
| 97 | + 'unsigned' => true, |
|
| 98 | + 'default' => 0 |
|
| 99 | + ], |
|
| 100 | + ]; |
|
| 101 | 101 | |
| 102 | - $this->dbforge->add_field($fields); |
|
| 103 | - $this->dbforge->add_key(['group_id', 'user_id']); |
|
| 104 | - $this->dbforge->create_table('auth_groups_users', true, config_item('migration_create_table_attr')); |
|
| 105 | - } |
|
| 102 | + $this->dbforge->add_field($fields); |
|
| 103 | + $this->dbforge->add_key(['group_id', 'user_id']); |
|
| 104 | + $this->dbforge->create_table('auth_groups_users', true, config_item('migration_create_table_attr')); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - //-------------------------------------------------------------------- |
|
| 107 | + //-------------------------------------------------------------------- |
|
| 108 | 108 | |
| 109 | - public function down () |
|
| 110 | - { |
|
| 109 | + public function down () |
|
| 110 | + { |
|
| 111 | 111 | $this->dbforge->drop_table('auth_groups'); |
| 112 | 112 | $this->dbforge->drop_table('auth_permissions'); |
| 113 | 113 | $this->dbforge->drop_table('auth_groups_permissions'); |
| 114 | 114 | $this->dbforge->drop_table('auth_groups_users'); |
| 115 | - } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - //-------------------------------------------------------------------- |
|
| 117 | + //-------------------------------------------------------------------- |
|
| 118 | 118 | |
| 119 | 119 | } |
@@ -10,48 +10,48 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class Migration_Createsessiontable extends CI_Migration { |
| 12 | 12 | |
| 13 | - public function up () |
|
| 14 | - { |
|
| 15 | - $fields = array( |
|
| 16 | - 'id' => array( |
|
| 17 | - 'type' => 'varchar', |
|
| 18 | - 'constraint' => 40, |
|
| 19 | - 'null' => false |
|
| 20 | - ), |
|
| 21 | - 'ip_address' => array( |
|
| 22 | - 'type' => 'varchar', |
|
| 23 | - 'constraint' => 45, |
|
| 24 | - 'null' => false |
|
| 25 | - ), |
|
| 26 | - 'timestamp' => array( |
|
| 27 | - 'type' => 'int', |
|
| 28 | - 'constraint' => 10, |
|
| 29 | - 'unsigned' => true, |
|
| 30 | - 'default' => '0', |
|
| 31 | - 'null' => false, |
|
| 32 | - ), |
|
| 33 | - 'data' => array( |
|
| 34 | - 'type' => 'blob', |
|
| 35 | - 'null' => false |
|
| 36 | - ) |
|
| 37 | - ); |
|
| 38 | - |
|
| 39 | - $this->dbforge->add_field($fields); |
|
| 40 | - |
|
| 41 | - $this->dbforge->add_key('id', TRUE); |
|
| 42 | - $this->dbforge->add_key('ip_address', TRUE); |
|
| 43 | - $this->dbforge->add_key('ci_sessions_timestamp'); |
|
| 44 | - |
|
| 45 | - $this->dbforge->create_table('ci_sessions', true, config_item('migration_create_table_attr')); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - //-------------------------------------------------------------------- |
|
| 49 | - |
|
| 50 | - public function down () |
|
| 51 | - { |
|
| 52 | - $this->dbforge->drop_table('ci_sessions'); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - //-------------------------------------------------------------------- |
|
| 13 | + public function up () |
|
| 14 | + { |
|
| 15 | + $fields = array( |
|
| 16 | + 'id' => array( |
|
| 17 | + 'type' => 'varchar', |
|
| 18 | + 'constraint' => 40, |
|
| 19 | + 'null' => false |
|
| 20 | + ), |
|
| 21 | + 'ip_address' => array( |
|
| 22 | + 'type' => 'varchar', |
|
| 23 | + 'constraint' => 45, |
|
| 24 | + 'null' => false |
|
| 25 | + ), |
|
| 26 | + 'timestamp' => array( |
|
| 27 | + 'type' => 'int', |
|
| 28 | + 'constraint' => 10, |
|
| 29 | + 'unsigned' => true, |
|
| 30 | + 'default' => '0', |
|
| 31 | + 'null' => false, |
|
| 32 | + ), |
|
| 33 | + 'data' => array( |
|
| 34 | + 'type' => 'blob', |
|
| 35 | + 'null' => false |
|
| 36 | + ) |
|
| 37 | + ); |
|
| 38 | + |
|
| 39 | + $this->dbforge->add_field($fields); |
|
| 40 | + |
|
| 41 | + $this->dbforge->add_key('id', TRUE); |
|
| 42 | + $this->dbforge->add_key('ip_address', TRUE); |
|
| 43 | + $this->dbforge->add_key('ci_sessions_timestamp'); |
|
| 44 | + |
|
| 45 | + $this->dbforge->create_table('ci_sessions', true, config_item('migration_create_table_attr')); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + //-------------------------------------------------------------------- |
|
| 49 | + |
|
| 50 | + public function down () |
|
| 51 | + { |
|
| 52 | + $this->dbforge->drop_table('ci_sessions'); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + //-------------------------------------------------------------------- |
|
| 56 | 56 | |
| 57 | 57 | } |
@@ -10,7 +10,7 @@ |
||
| 10 | 10 | |
| 11 | 11 | public function run() |
| 12 | 12 | { |
| 13 | - $flat = new \Myth\Auth\FlatAuthorization(); |
|
| 13 | + $flat = new \Myth\Auth\FlatAuthorization(); |
|
| 14 | 14 | |
| 15 | 15 | $flat->createPermission('viewPosts', 'View the blog posts.'); |
| 16 | 16 | $flat->createPermission('managePosts', 'Manage the blog posts.'); |
@@ -8,9 +8,9 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | class TestSeeder extends Seeder { |
| 10 | 10 | |
| 11 | - public function run() |
|
| 12 | - { |
|
| 13 | - /* |
|
| 11 | + public function run() |
|
| 12 | + { |
|
| 13 | + /* |
|
| 14 | 14 | Here, you can do anything you need to do to get your |
| 15 | 15 | database in the desired state. The following tools are ready for you: |
| 16 | 16 | |
@@ -23,8 +23,8 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | $this->call('UserSeeder'); |
| 25 | 25 | */ |
| 26 | - } |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - //-------------------------------------------------------------------- |
|
| 28 | + //-------------------------------------------------------------------- |
|
| 29 | 29 | |
| 30 | 30 | } |
@@ -3,117 +3,117 @@ |
||
| 3 | 3 | if (! class_exists('MY_Form_validation')) |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | - class MY_Form_validation extends CI_Form_validation { |
|
| 7 | - /** |
|
| 8 | - * @var object The CodeIgniter core object. |
|
| 9 | - */ |
|
| 10 | - public $CI; |
|
| 11 | - |
|
| 12 | - //-------------------------------------------------------------------- |
|
| 13 | - |
|
| 14 | - /** |
|
| 15 | - * Check if the field has an error associated with it. |
|
| 16 | - * |
|
| 17 | - * @param string $field The name of the field |
|
| 18 | - * |
|
| 19 | - * @return bool |
|
| 20 | - */ |
|
| 21 | - public function has_error( $field = NULL ) |
|
| 22 | - { |
|
| 23 | - if ( empty( $field ) ) |
|
| 24 | - { |
|
| 25 | - return FALSE; |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - return ! empty( $this->_field_data[ $field ]['error'] ); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - //-------------------------------------------------------------------- |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Performs the actual form validation |
|
| 35 | - * |
|
| 36 | - * @param string $module Name of the module |
|
| 37 | - * @param string $group Name of the group array containing the rules |
|
| 38 | - * |
|
| 39 | - * @return bool Success or Failure |
|
| 40 | - */ |
|
| 41 | - public function run($group = '', $module = '') |
|
| 42 | - { |
|
| 43 | - is_object($module) && $this->CI =& $module; |
|
| 44 | - return parent::run($group); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - //-------------------------------------------------------------------- |
|
| 48 | - |
|
| 49 | - //-------------------------------------------------------------------- |
|
| 50 | - // Validation Rules |
|
| 51 | - //-------------------------------------------------------------------- |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Checks that a value is unique in the database. |
|
| 55 | - * |
|
| 56 | - * i.e. '…|required|unique[users.name,users.id]|trim…' |
|
| 57 | - * |
|
| 58 | - * <code> |
|
| 59 | - * "unique[tablename.fieldname,tablename.(primaryKey-used-for-updates)]" |
|
| 60 | - * </code> |
|
| 61 | - * |
|
| 62 | - * @author Adapted from Burak Guzel <http://net.tutsplus.com/tutorials/php/6-codeigniter-hacks-for-the-masters/> |
|
| 63 | - * |
|
| 64 | - * @param mixed $value The value to be checked. |
|
| 65 | - * @param mixed $params The table and field to check against, if a second |
|
| 66 | - * field is passed in this is used as "AND NOT EQUAL". |
|
| 67 | - * |
|
| 68 | - * @return bool True if the value is unique for that field, else false. |
|
| 69 | - */ |
|
| 70 | - public function is_unique( $value, $params ) |
|
| 71 | - { |
|
| 72 | - if ( empty( $this->CI->db ) ) |
|
| 73 | - { |
|
| 74 | - $this->CI->load->database(); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - // Allow for more than 1 parameter. |
|
| 78 | - $fields = explode( ",", $params ); |
|
| 79 | - |
|
| 80 | - // Extract the table and field from the first parameter. |
|
| 81 | - list( $table, $field ) = explode( '.', $fields[0], 2 ); |
|
| 82 | - |
|
| 83 | - // Setup the db request. |
|
| 84 | - $this->CI->db->select( $field ) |
|
| 85 | - ->from( $table ) |
|
| 86 | - ->where( $field, $value ) |
|
| 87 | - ->limit( 1 ); |
|
| 88 | - |
|
| 89 | - // Check whether a second parameter was passed to be used as an |
|
| 90 | - // "AND NOT EQUAL" where clause |
|
| 91 | - // eg "select * from users where users.name='test' AND users.id != 4 |
|
| 92 | - if ( isset( $fields[1] ) ) |
|
| 93 | - { |
|
| 94 | - // Extract the table and field from the second parameter |
|
| 95 | - list( $where_table, $where_field ) = explode( '.', $fields[1], 2 ); |
|
| 96 | - |
|
| 97 | - // Get the value from the post's $where_field. If the value is set, |
|
| 98 | - // add "AND NOT EQUAL" where clause. |
|
| 99 | - $where_value = $this->CI->input->post( $where_field ); |
|
| 100 | - if ( isset( $where_value ) ) |
|
| 101 | - { |
|
| 102 | - $this->CI->db->where( "{$where_table}.{$where_field} !=", $where_value ); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // If any rows are returned from the database, validation fails |
|
| 107 | - $query = $this->CI->db->get(); |
|
| 108 | - if ( $query->row() ) |
|
| 109 | - { |
|
| 110 | - $this->CI->form_validation->set_message( 'unique', 'The %s field is already in use.' ); |
|
| 111 | - |
|
| 112 | - return FALSE; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - return TRUE; |
|
| 116 | - } |
|
| 117 | - } |
|
| 6 | + class MY_Form_validation extends CI_Form_validation { |
|
| 7 | + /** |
|
| 8 | + * @var object The CodeIgniter core object. |
|
| 9 | + */ |
|
| 10 | + public $CI; |
|
| 11 | + |
|
| 12 | + //-------------------------------------------------------------------- |
|
| 13 | + |
|
| 14 | + /** |
|
| 15 | + * Check if the field has an error associated with it. |
|
| 16 | + * |
|
| 17 | + * @param string $field The name of the field |
|
| 18 | + * |
|
| 19 | + * @return bool |
|
| 20 | + */ |
|
| 21 | + public function has_error( $field = NULL ) |
|
| 22 | + { |
|
| 23 | + if ( empty( $field ) ) |
|
| 24 | + { |
|
| 25 | + return FALSE; |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + return ! empty( $this->_field_data[ $field ]['error'] ); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + //-------------------------------------------------------------------- |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Performs the actual form validation |
|
| 35 | + * |
|
| 36 | + * @param string $module Name of the module |
|
| 37 | + * @param string $group Name of the group array containing the rules |
|
| 38 | + * |
|
| 39 | + * @return bool Success or Failure |
|
| 40 | + */ |
|
| 41 | + public function run($group = '', $module = '') |
|
| 42 | + { |
|
| 43 | + is_object($module) && $this->CI =& $module; |
|
| 44 | + return parent::run($group); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + //-------------------------------------------------------------------- |
|
| 48 | + |
|
| 49 | + //-------------------------------------------------------------------- |
|
| 50 | + // Validation Rules |
|
| 51 | + //-------------------------------------------------------------------- |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Checks that a value is unique in the database. |
|
| 55 | + * |
|
| 56 | + * i.e. '…|required|unique[users.name,users.id]|trim…' |
|
| 57 | + * |
|
| 58 | + * <code> |
|
| 59 | + * "unique[tablename.fieldname,tablename.(primaryKey-used-for-updates)]" |
|
| 60 | + * </code> |
|
| 61 | + * |
|
| 62 | + * @author Adapted from Burak Guzel <http://net.tutsplus.com/tutorials/php/6-codeigniter-hacks-for-the-masters/> |
|
| 63 | + * |
|
| 64 | + * @param mixed $value The value to be checked. |
|
| 65 | + * @param mixed $params The table and field to check against, if a second |
|
| 66 | + * field is passed in this is used as "AND NOT EQUAL". |
|
| 67 | + * |
|
| 68 | + * @return bool True if the value is unique for that field, else false. |
|
| 69 | + */ |
|
| 70 | + public function is_unique( $value, $params ) |
|
| 71 | + { |
|
| 72 | + if ( empty( $this->CI->db ) ) |
|
| 73 | + { |
|
| 74 | + $this->CI->load->database(); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + // Allow for more than 1 parameter. |
|
| 78 | + $fields = explode( ",", $params ); |
|
| 79 | + |
|
| 80 | + // Extract the table and field from the first parameter. |
|
| 81 | + list( $table, $field ) = explode( '.', $fields[0], 2 ); |
|
| 82 | + |
|
| 83 | + // Setup the db request. |
|
| 84 | + $this->CI->db->select( $field ) |
|
| 85 | + ->from( $table ) |
|
| 86 | + ->where( $field, $value ) |
|
| 87 | + ->limit( 1 ); |
|
| 88 | + |
|
| 89 | + // Check whether a second parameter was passed to be used as an |
|
| 90 | + // "AND NOT EQUAL" where clause |
|
| 91 | + // eg "select * from users where users.name='test' AND users.id != 4 |
|
| 92 | + if ( isset( $fields[1] ) ) |
|
| 93 | + { |
|
| 94 | + // Extract the table and field from the second parameter |
|
| 95 | + list( $where_table, $where_field ) = explode( '.', $fields[1], 2 ); |
|
| 96 | + |
|
| 97 | + // Get the value from the post's $where_field. If the value is set, |
|
| 98 | + // add "AND NOT EQUAL" where clause. |
|
| 99 | + $where_value = $this->CI->input->post( $where_field ); |
|
| 100 | + if ( isset( $where_value ) ) |
|
| 101 | + { |
|
| 102 | + $this->CI->db->where( "{$where_table}.{$where_field} !=", $where_value ); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // If any rows are returned from the database, validation fails |
|
| 107 | + $query = $this->CI->db->get(); |
|
| 108 | + if ( $query->row() ) |
|
| 109 | + { |
|
| 110 | + $this->CI->form_validation->set_message( 'unique', 'The %s field is already in use.' ); |
|
| 111 | + |
|
| 112 | + return FALSE; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + return TRUE; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | 119 | } |
@@ -51,415 +51,415 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | class CI_Migration { |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Whether the library is enabled |
|
| 56 | - * |
|
| 57 | - * @var bool |
|
| 58 | - */ |
|
| 59 | - protected $_migration_enabled = FALSE; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Migration numbering type |
|
| 63 | - * |
|
| 64 | - * @var bool |
|
| 65 | - */ |
|
| 66 | - protected $_migration_type = 'sequential'; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Path to migration classes |
|
| 70 | - * |
|
| 71 | - * @var string |
|
| 72 | - */ |
|
| 73 | - protected $_migration_paths = NULL; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Current migration version |
|
| 77 | - * |
|
| 78 | - * @var mixed |
|
| 79 | - */ |
|
| 80 | - protected $_migration_version = 0; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Database table with migration info |
|
| 84 | - * |
|
| 85 | - * @var string |
|
| 86 | - */ |
|
| 87 | - protected $_migration_table = 'migrations'; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Whether to automatically run migrations |
|
| 91 | - * |
|
| 92 | - * @var bool |
|
| 93 | - */ |
|
| 94 | - protected $_migration_auto_latest = FALSE; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Migration basename regex |
|
| 98 | - * |
|
| 99 | - * @var bool |
|
| 100 | - */ |
|
| 101 | - protected $_migration_regex = NULL; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Error message |
|
| 105 | - * |
|
| 106 | - * @var string |
|
| 107 | - */ |
|
| 108 | - protected $_error_string = ''; |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Initialize Migration Class |
|
| 112 | - * |
|
| 113 | - * @param array $config |
|
| 114 | - * @return void |
|
| 115 | - */ |
|
| 116 | - public function __construct($config = array()) |
|
| 117 | - { |
|
| 118 | - // Only run this constructor on main library load |
|
| 119 | - if ( ! in_array(get_class($this), array('CI_Migration', config_item('subclass_prefix').'Migration'), TRUE)) |
|
| 120 | - { |
|
| 121 | - return; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - foreach ($config as $key => $val) |
|
| 125 | - { |
|
| 126 | - $this->{'_'.$key} = $val; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - log_message('debug', 'Migrations class initialized'); |
|
| 130 | - |
|
| 131 | - // Are they trying to use migrations while it is disabled? |
|
| 132 | - if ($this->_migration_enabled !== TRUE) |
|
| 133 | - { |
|
| 134 | - show_error('Migrations has been loaded but is disabled or set up incorrectly.'); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - // If not set, set it |
|
| 138 | - count($this->_migration_paths) OR $this->_migration_paths = array(APPPATH.'database/migrations/'); |
|
| 139 | - |
|
| 140 | - // Add trailing slash if not set |
|
| 141 | - foreach ($this->_migration_paths as $alias => $path) { |
|
| 142 | - $this->_migration_paths[$alias] = rtrim($this->_migration_paths[$alias], '/') . '/'; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - // Load migration language |
|
| 146 | - $this->lang->load('migration'); |
|
| 147 | - |
|
| 148 | - // They'll probably be using dbforge |
|
| 149 | - $this->load->dbforge(); |
|
| 150 | - |
|
| 151 | - // Make sure the migration table name was set. |
|
| 152 | - if (empty($this->_migration_table)) |
|
| 153 | - { |
|
| 154 | - show_error('Migrations configuration file (migration.php) must have "migration_table" set.'); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // Migration basename regex |
|
| 158 | - $this->_migration_regex = ($this->_migration_type === 'timestamp') |
|
| 159 | - ? '/^\d{14}_(\w+)$/' |
|
| 160 | - : '/^\d{3}_(\w+)$/'; |
|
| 161 | - |
|
| 162 | - // Make sure a valid migration numbering type was set. |
|
| 163 | - if ( ! in_array($this->_migration_type, array('sequential', 'timestamp'))) |
|
| 164 | - { |
|
| 165 | - show_error('An invalid migration numbering type was specified: '.$this->_migration_type); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - // If the migrations table is missing, make it |
|
| 169 | - if ( ! $this->db->table_exists($this->_migration_table)) |
|
| 170 | - { |
|
| 171 | - $this->dbforge->add_field(array( |
|
| 172 | - 'version' => array('type' => 'BIGINT', 'constraint' => 20), |
|
| 173 | - 'alias' => array('type' => 'VARCHAR', 'constraint' => 255), |
|
| 174 | - 'ondate' => array('type' => 'DATETIME') |
|
| 175 | - )); |
|
| 176 | - |
|
| 177 | - $this->dbforge->add_key('alias'); |
|
| 178 | - |
|
| 179 | - $this->dbforge->create_table($this->_migration_table, TRUE); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - // Do we auto migrate to the latest migration? |
|
| 183 | - if ($this->_migration_auto_latest === TRUE && ! $this->latest()) |
|
| 184 | - { |
|
| 185 | - show_error($this->error_string()); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - // -------------------------------------------------------------------- |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Migrate to a schema version |
|
| 194 | - * |
|
| 195 | - * Calls each migration step required to get to the schema version of |
|
| 196 | - * choice |
|
| 197 | - * |
|
| 198 | - * @param string $type Any key from _migration_paths, or {module_name} |
|
| 199 | - * @param string $target_version Target schema version |
|
| 200 | - * |
|
| 201 | - * @return mixed TRUE if already latest, FALSE if failed, string if upgraded |
|
| 202 | - */ |
|
| 203 | - public function version($type='all', $target_version) |
|
| 204 | - { |
|
| 205 | - // Note: We use strings, so that timestamp versions work on 32-bit systems |
|
| 206 | - $current_version = $this->get_version($type); |
|
| 207 | - |
|
| 208 | - if ($this->_migration_type === 'sequential') |
|
| 209 | - { |
|
| 210 | - $target_version = sprintf('%03d', $target_version); |
|
| 211 | - } |
|
| 212 | - else |
|
| 213 | - { |
|
| 214 | - $target_version = (string) $target_version; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - $migrations = $this->find_migrations($type); |
|
| 218 | - |
|
| 219 | - if ($target_version > 0 && ! isset($migrations[$target_version])) |
|
| 220 | - { |
|
| 221 | - $this->_error_string = sprintf($this->lang->line('migration_not_found'), $target_version); |
|
| 222 | - return FALSE; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - if ($target_version > $current_version) |
|
| 226 | - { |
|
| 227 | - // Moving Up |
|
| 228 | - $method = 'up'; |
|
| 229 | - } |
|
| 230 | - else |
|
| 231 | - { |
|
| 232 | - // Moving Down, apply in reverse order |
|
| 233 | - $method = 'down'; |
|
| 234 | - krsort($migrations); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - if (empty($migrations)) |
|
| 238 | - { |
|
| 239 | - return TRUE; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - $previous = FALSE; |
|
| 243 | - |
|
| 244 | - // Validate all available migrations, and run the ones within our target range |
|
| 245 | - foreach ($migrations as $number => $file) |
|
| 246 | - { |
|
| 247 | - // Check for sequence gaps |
|
| 248 | - if ($this->_migration_type === 'sequential' && $previous !== FALSE && abs($number - $previous) > 1) |
|
| 249 | - { |
|
| 250 | - $this->_error_string = sprintf($this->lang->line('migration_sequence_gap'), $number); |
|
| 251 | - return FALSE; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - include_once($file); |
|
| 255 | - $class = 'Migration_'.ucfirst(strtolower($this->_get_migration_name(basename($file, '.php')))); |
|
| 256 | - |
|
| 257 | - // Validate the migration file structure |
|
| 258 | - if ( ! class_exists($class, FALSE)) |
|
| 259 | - { |
|
| 260 | - $this->_error_string = sprintf($this->lang->line('migration_class_doesnt_exist'), $class); |
|
| 261 | - return FALSE; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - $previous = $number; |
|
| 265 | - |
|
| 266 | - // Run migrations that are inside the target range |
|
| 267 | - if ( |
|
| 268 | - ($method === 'up' && $number > $current_version && $number <= $target_version) OR |
|
| 269 | - ($method === 'down' && $number <= $current_version && $number > $target_version) |
|
| 270 | - ) |
|
| 271 | - { |
|
| 272 | - $instance = new $class(); |
|
| 273 | - if ( ! is_callable(array($instance, $method))) |
|
| 274 | - { |
|
| 275 | - $this->_error_string = sprintf($this->lang->line('migration_missing_'.$method.'_method'), $class); |
|
| 276 | - return FALSE; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - log_message('debug', 'Migrating '.$method.' from version '.$current_version.' to version '.$number); |
|
| 280 | - call_user_func(array($instance, $method)); |
|
| 281 | - $current_version = $number; |
|
| 282 | - $this->_update_version($type, $current_version); |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - // This is necessary when moving down, since the the last migration applied |
|
| 287 | - // will be the down() method for the next migration up from the target |
|
| 288 | - if ($current_version <> $target_version) |
|
| 289 | - { |
|
| 290 | - $current_version = $target_version; |
|
| 291 | - $this->_update_version($type, $current_version); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - log_message('debug', 'Finished migrating to '.$current_version); |
|
| 295 | - |
|
| 296 | - return $current_version; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - // -------------------------------------------------------------------- |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Sets the schema to the latest migration |
|
| 303 | - * |
|
| 304 | - * @param string $type Any key from _migration_paths, or {module_name} |
|
| 305 | - * |
|
| 306 | - * @return mixed TRUE if already latest, FALSE if failed, string if upgraded |
|
| 307 | - */ |
|
| 308 | - public function latest($type='app') |
|
| 309 | - { |
|
| 310 | - $last_migration = $this->get_latest($type); |
|
| 311 | - |
|
| 312 | - // Calculate the last migration step from existing migration |
|
| 313 | - // filenames and proceed to the standard version migration |
|
| 314 | - return $this->version($type, $this->_get_migration_number($last_migration)); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - // -------------------------------------------------------------------- |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Retrieves the latest migration version available. |
|
| 321 | - * |
|
| 322 | - * @param string $type Any key from _migration_paths, or {module_name} |
|
| 323 | - * |
|
| 324 | - * @return bool|string |
|
| 325 | - */ |
|
| 326 | - public function get_latest($type='app') |
|
| 327 | - { |
|
| 328 | - $migrations = $this->find_migrations($type); |
|
| 329 | - |
|
| 330 | - if (empty($migrations)) |
|
| 331 | - { |
|
| 332 | - $this->_error_string = $this->lang->line('migration_none_found'); |
|
| 333 | - return FALSE; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - return basename(end($migrations)); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - //-------------------------------------------------------------------- |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Sets the schema to the migration version set in config |
|
| 345 | - * |
|
| 346 | - * @return mixed TRUE if already current, FALSE if failed, string if upgraded |
|
| 347 | - */ |
|
| 348 | - public function current() |
|
| 349 | - { |
|
| 350 | - return $this->version($this->_migration_version); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - // -------------------------------------------------------------------- |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * Error string |
|
| 357 | - * |
|
| 358 | - * @return string Error message returned as a string |
|
| 359 | - */ |
|
| 360 | - public function error_string() |
|
| 361 | - { |
|
| 362 | - return $this->_error_string; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - // -------------------------------------------------------------------- |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * Retrieves list of available migration scripts |
|
| 369 | - * |
|
| 370 | - * @return array list of migration file paths sorted by version |
|
| 371 | - */ |
|
| 372 | - public function find_migrations($type='app') |
|
| 373 | - { |
|
| 374 | - $migrations = array(); |
|
| 375 | - |
|
| 376 | - $path = $this->determine_migration_path($type); |
|
| 377 | - |
|
| 378 | - // Load all *_*.php files in the migrations path |
|
| 379 | - foreach (glob($path.'*_*.php') as $file) |
|
| 380 | - { |
|
| 381 | - $name = basename($file, '.php'); |
|
| 382 | - |
|
| 383 | - // Filter out non-migration files |
|
| 384 | - if (preg_match($this->_migration_regex, $name)) |
|
| 385 | - { |
|
| 386 | - $number = $this->_get_migration_number($name); |
|
| 387 | - |
|
| 388 | - // There cannot be duplicate migration numbers |
|
| 389 | - if (isset($migrations[$number])) |
|
| 390 | - { |
|
| 391 | - $this->_error_string = sprintf($this->lang->line('migration_multiple_version'), $number); |
|
| 392 | - show_error($this->_error_string); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - $migrations[$number] = $file; |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - ksort($migrations); |
|
| 400 | - return $migrations; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - // -------------------------------------------------------------------- |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * Retrieves current schema version |
|
| 407 | - * |
|
| 408 | - * @return string Current migration version |
|
| 409 | - */ |
|
| 410 | - public function get_version($type='app') |
|
| 411 | - { |
|
| 412 | - $row = $this->db->select('version') |
|
| 413 | - ->where('alias', $type) |
|
| 414 | - ->get($this->_migration_table) |
|
| 415 | - ->row(); |
|
| 416 | - |
|
| 417 | - return $row ? $row->version : '0'; |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - // -------------------------------------------------------------------- |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Given the string for the name of the file, will |
|
| 424 | - * generate the rest of the filename based on the current |
|
| 425 | - * $config['migration_type'] setting. |
|
| 426 | - * |
|
| 427 | - * @param $name |
|
| 428 | - * @return string The final name (with extension) |
|
| 429 | - */ |
|
| 430 | - public function make_name($name) |
|
| 431 | - { |
|
| 432 | - if (empty($name)) |
|
| 433 | - { |
|
| 434 | - return null; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - if ($this->_migration_type == 'timestamp') |
|
| 438 | - { |
|
| 439 | - $prefix = date('YmdHis'); |
|
| 440 | - } |
|
| 441 | - else |
|
| 442 | - { |
|
| 443 | - $prefix = str_pad($this->get_version() + 1, 3, '0', STR_PAD_LEFT); |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - return $prefix .'_'. ucfirst(strtolower($name)) .'.php'; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - //-------------------------------------------------------------------- |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Enable the use of CI super-global |
|
| 453 | - * |
|
| 454 | - * @param string $var |
|
| 455 | - * @return mixed |
|
| 456 | - */ |
|
| 457 | - public function __get($var) |
|
| 458 | - { |
|
| 459 | - return get_instance()->$var; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - //-------------------------------------------------------------------- |
|
| 54 | + /** |
|
| 55 | + * Whether the library is enabled |
|
| 56 | + * |
|
| 57 | + * @var bool |
|
| 58 | + */ |
|
| 59 | + protected $_migration_enabled = FALSE; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Migration numbering type |
|
| 63 | + * |
|
| 64 | + * @var bool |
|
| 65 | + */ |
|
| 66 | + protected $_migration_type = 'sequential'; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Path to migration classes |
|
| 70 | + * |
|
| 71 | + * @var string |
|
| 72 | + */ |
|
| 73 | + protected $_migration_paths = NULL; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Current migration version |
|
| 77 | + * |
|
| 78 | + * @var mixed |
|
| 79 | + */ |
|
| 80 | + protected $_migration_version = 0; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Database table with migration info |
|
| 84 | + * |
|
| 85 | + * @var string |
|
| 86 | + */ |
|
| 87 | + protected $_migration_table = 'migrations'; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Whether to automatically run migrations |
|
| 91 | + * |
|
| 92 | + * @var bool |
|
| 93 | + */ |
|
| 94 | + protected $_migration_auto_latest = FALSE; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Migration basename regex |
|
| 98 | + * |
|
| 99 | + * @var bool |
|
| 100 | + */ |
|
| 101 | + protected $_migration_regex = NULL; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Error message |
|
| 105 | + * |
|
| 106 | + * @var string |
|
| 107 | + */ |
|
| 108 | + protected $_error_string = ''; |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Initialize Migration Class |
|
| 112 | + * |
|
| 113 | + * @param array $config |
|
| 114 | + * @return void |
|
| 115 | + */ |
|
| 116 | + public function __construct($config = array()) |
|
| 117 | + { |
|
| 118 | + // Only run this constructor on main library load |
|
| 119 | + if ( ! in_array(get_class($this), array('CI_Migration', config_item('subclass_prefix').'Migration'), TRUE)) |
|
| 120 | + { |
|
| 121 | + return; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + foreach ($config as $key => $val) |
|
| 125 | + { |
|
| 126 | + $this->{'_'.$key} = $val; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + log_message('debug', 'Migrations class initialized'); |
|
| 130 | + |
|
| 131 | + // Are they trying to use migrations while it is disabled? |
|
| 132 | + if ($this->_migration_enabled !== TRUE) |
|
| 133 | + { |
|
| 134 | + show_error('Migrations has been loaded but is disabled or set up incorrectly.'); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + // If not set, set it |
|
| 138 | + count($this->_migration_paths) OR $this->_migration_paths = array(APPPATH.'database/migrations/'); |
|
| 139 | + |
|
| 140 | + // Add trailing slash if not set |
|
| 141 | + foreach ($this->_migration_paths as $alias => $path) { |
|
| 142 | + $this->_migration_paths[$alias] = rtrim($this->_migration_paths[$alias], '/') . '/'; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + // Load migration language |
|
| 146 | + $this->lang->load('migration'); |
|
| 147 | + |
|
| 148 | + // They'll probably be using dbforge |
|
| 149 | + $this->load->dbforge(); |
|
| 150 | + |
|
| 151 | + // Make sure the migration table name was set. |
|
| 152 | + if (empty($this->_migration_table)) |
|
| 153 | + { |
|
| 154 | + show_error('Migrations configuration file (migration.php) must have "migration_table" set.'); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // Migration basename regex |
|
| 158 | + $this->_migration_regex = ($this->_migration_type === 'timestamp') |
|
| 159 | + ? '/^\d{14}_(\w+)$/' |
|
| 160 | + : '/^\d{3}_(\w+)$/'; |
|
| 161 | + |
|
| 162 | + // Make sure a valid migration numbering type was set. |
|
| 163 | + if ( ! in_array($this->_migration_type, array('sequential', 'timestamp'))) |
|
| 164 | + { |
|
| 165 | + show_error('An invalid migration numbering type was specified: '.$this->_migration_type); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + // If the migrations table is missing, make it |
|
| 169 | + if ( ! $this->db->table_exists($this->_migration_table)) |
|
| 170 | + { |
|
| 171 | + $this->dbforge->add_field(array( |
|
| 172 | + 'version' => array('type' => 'BIGINT', 'constraint' => 20), |
|
| 173 | + 'alias' => array('type' => 'VARCHAR', 'constraint' => 255), |
|
| 174 | + 'ondate' => array('type' => 'DATETIME') |
|
| 175 | + )); |
|
| 176 | + |
|
| 177 | + $this->dbforge->add_key('alias'); |
|
| 178 | + |
|
| 179 | + $this->dbforge->create_table($this->_migration_table, TRUE); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + // Do we auto migrate to the latest migration? |
|
| 183 | + if ($this->_migration_auto_latest === TRUE && ! $this->latest()) |
|
| 184 | + { |
|
| 185 | + show_error($this->error_string()); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + // -------------------------------------------------------------------- |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Migrate to a schema version |
|
| 194 | + * |
|
| 195 | + * Calls each migration step required to get to the schema version of |
|
| 196 | + * choice |
|
| 197 | + * |
|
| 198 | + * @param string $type Any key from _migration_paths, or {module_name} |
|
| 199 | + * @param string $target_version Target schema version |
|
| 200 | + * |
|
| 201 | + * @return mixed TRUE if already latest, FALSE if failed, string if upgraded |
|
| 202 | + */ |
|
| 203 | + public function version($type='all', $target_version) |
|
| 204 | + { |
|
| 205 | + // Note: We use strings, so that timestamp versions work on 32-bit systems |
|
| 206 | + $current_version = $this->get_version($type); |
|
| 207 | + |
|
| 208 | + if ($this->_migration_type === 'sequential') |
|
| 209 | + { |
|
| 210 | + $target_version = sprintf('%03d', $target_version); |
|
| 211 | + } |
|
| 212 | + else |
|
| 213 | + { |
|
| 214 | + $target_version = (string) $target_version; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + $migrations = $this->find_migrations($type); |
|
| 218 | + |
|
| 219 | + if ($target_version > 0 && ! isset($migrations[$target_version])) |
|
| 220 | + { |
|
| 221 | + $this->_error_string = sprintf($this->lang->line('migration_not_found'), $target_version); |
|
| 222 | + return FALSE; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + if ($target_version > $current_version) |
|
| 226 | + { |
|
| 227 | + // Moving Up |
|
| 228 | + $method = 'up'; |
|
| 229 | + } |
|
| 230 | + else |
|
| 231 | + { |
|
| 232 | + // Moving Down, apply in reverse order |
|
| 233 | + $method = 'down'; |
|
| 234 | + krsort($migrations); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + if (empty($migrations)) |
|
| 238 | + { |
|
| 239 | + return TRUE; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + $previous = FALSE; |
|
| 243 | + |
|
| 244 | + // Validate all available migrations, and run the ones within our target range |
|
| 245 | + foreach ($migrations as $number => $file) |
|
| 246 | + { |
|
| 247 | + // Check for sequence gaps |
|
| 248 | + if ($this->_migration_type === 'sequential' && $previous !== FALSE && abs($number - $previous) > 1) |
|
| 249 | + { |
|
| 250 | + $this->_error_string = sprintf($this->lang->line('migration_sequence_gap'), $number); |
|
| 251 | + return FALSE; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + include_once($file); |
|
| 255 | + $class = 'Migration_'.ucfirst(strtolower($this->_get_migration_name(basename($file, '.php')))); |
|
| 256 | + |
|
| 257 | + // Validate the migration file structure |
|
| 258 | + if ( ! class_exists($class, FALSE)) |
|
| 259 | + { |
|
| 260 | + $this->_error_string = sprintf($this->lang->line('migration_class_doesnt_exist'), $class); |
|
| 261 | + return FALSE; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + $previous = $number; |
|
| 265 | + |
|
| 266 | + // Run migrations that are inside the target range |
|
| 267 | + if ( |
|
| 268 | + ($method === 'up' && $number > $current_version && $number <= $target_version) OR |
|
| 269 | + ($method === 'down' && $number <= $current_version && $number > $target_version) |
|
| 270 | + ) |
|
| 271 | + { |
|
| 272 | + $instance = new $class(); |
|
| 273 | + if ( ! is_callable(array($instance, $method))) |
|
| 274 | + { |
|
| 275 | + $this->_error_string = sprintf($this->lang->line('migration_missing_'.$method.'_method'), $class); |
|
| 276 | + return FALSE; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + log_message('debug', 'Migrating '.$method.' from version '.$current_version.' to version '.$number); |
|
| 280 | + call_user_func(array($instance, $method)); |
|
| 281 | + $current_version = $number; |
|
| 282 | + $this->_update_version($type, $current_version); |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + // This is necessary when moving down, since the the last migration applied |
|
| 287 | + // will be the down() method for the next migration up from the target |
|
| 288 | + if ($current_version <> $target_version) |
|
| 289 | + { |
|
| 290 | + $current_version = $target_version; |
|
| 291 | + $this->_update_version($type, $current_version); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + log_message('debug', 'Finished migrating to '.$current_version); |
|
| 295 | + |
|
| 296 | + return $current_version; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + // -------------------------------------------------------------------- |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Sets the schema to the latest migration |
|
| 303 | + * |
|
| 304 | + * @param string $type Any key from _migration_paths, or {module_name} |
|
| 305 | + * |
|
| 306 | + * @return mixed TRUE if already latest, FALSE if failed, string if upgraded |
|
| 307 | + */ |
|
| 308 | + public function latest($type='app') |
|
| 309 | + { |
|
| 310 | + $last_migration = $this->get_latest($type); |
|
| 311 | + |
|
| 312 | + // Calculate the last migration step from existing migration |
|
| 313 | + // filenames and proceed to the standard version migration |
|
| 314 | + return $this->version($type, $this->_get_migration_number($last_migration)); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + // -------------------------------------------------------------------- |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Retrieves the latest migration version available. |
|
| 321 | + * |
|
| 322 | + * @param string $type Any key from _migration_paths, or {module_name} |
|
| 323 | + * |
|
| 324 | + * @return bool|string |
|
| 325 | + */ |
|
| 326 | + public function get_latest($type='app') |
|
| 327 | + { |
|
| 328 | + $migrations = $this->find_migrations($type); |
|
| 329 | + |
|
| 330 | + if (empty($migrations)) |
|
| 331 | + { |
|
| 332 | + $this->_error_string = $this->lang->line('migration_none_found'); |
|
| 333 | + return FALSE; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + return basename(end($migrations)); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + //-------------------------------------------------------------------- |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Sets the schema to the migration version set in config |
|
| 345 | + * |
|
| 346 | + * @return mixed TRUE if already current, FALSE if failed, string if upgraded |
|
| 347 | + */ |
|
| 348 | + public function current() |
|
| 349 | + { |
|
| 350 | + return $this->version($this->_migration_version); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + // -------------------------------------------------------------------- |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * Error string |
|
| 357 | + * |
|
| 358 | + * @return string Error message returned as a string |
|
| 359 | + */ |
|
| 360 | + public function error_string() |
|
| 361 | + { |
|
| 362 | + return $this->_error_string; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + // -------------------------------------------------------------------- |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * Retrieves list of available migration scripts |
|
| 369 | + * |
|
| 370 | + * @return array list of migration file paths sorted by version |
|
| 371 | + */ |
|
| 372 | + public function find_migrations($type='app') |
|
| 373 | + { |
|
| 374 | + $migrations = array(); |
|
| 375 | + |
|
| 376 | + $path = $this->determine_migration_path($type); |
|
| 377 | + |
|
| 378 | + // Load all *_*.php files in the migrations path |
|
| 379 | + foreach (glob($path.'*_*.php') as $file) |
|
| 380 | + { |
|
| 381 | + $name = basename($file, '.php'); |
|
| 382 | + |
|
| 383 | + // Filter out non-migration files |
|
| 384 | + if (preg_match($this->_migration_regex, $name)) |
|
| 385 | + { |
|
| 386 | + $number = $this->_get_migration_number($name); |
|
| 387 | + |
|
| 388 | + // There cannot be duplicate migration numbers |
|
| 389 | + if (isset($migrations[$number])) |
|
| 390 | + { |
|
| 391 | + $this->_error_string = sprintf($this->lang->line('migration_multiple_version'), $number); |
|
| 392 | + show_error($this->_error_string); |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + $migrations[$number] = $file; |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + ksort($migrations); |
|
| 400 | + return $migrations; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + // -------------------------------------------------------------------- |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * Retrieves current schema version |
|
| 407 | + * |
|
| 408 | + * @return string Current migration version |
|
| 409 | + */ |
|
| 410 | + public function get_version($type='app') |
|
| 411 | + { |
|
| 412 | + $row = $this->db->select('version') |
|
| 413 | + ->where('alias', $type) |
|
| 414 | + ->get($this->_migration_table) |
|
| 415 | + ->row(); |
|
| 416 | + |
|
| 417 | + return $row ? $row->version : '0'; |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + // -------------------------------------------------------------------- |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Given the string for the name of the file, will |
|
| 424 | + * generate the rest of the filename based on the current |
|
| 425 | + * $config['migration_type'] setting. |
|
| 426 | + * |
|
| 427 | + * @param $name |
|
| 428 | + * @return string The final name (with extension) |
|
| 429 | + */ |
|
| 430 | + public function make_name($name) |
|
| 431 | + { |
|
| 432 | + if (empty($name)) |
|
| 433 | + { |
|
| 434 | + return null; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + if ($this->_migration_type == 'timestamp') |
|
| 438 | + { |
|
| 439 | + $prefix = date('YmdHis'); |
|
| 440 | + } |
|
| 441 | + else |
|
| 442 | + { |
|
| 443 | + $prefix = str_pad($this->get_version() + 1, 3, '0', STR_PAD_LEFT); |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + return $prefix .'_'. ucfirst(strtolower($name)) .'.php'; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + //-------------------------------------------------------------------- |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Enable the use of CI super-global |
|
| 453 | + * |
|
| 454 | + * @param string $var |
|
| 455 | + * @return mixed |
|
| 456 | + */ |
|
| 457 | + public function __get($var) |
|
| 458 | + { |
|
| 459 | + return get_instance()->$var; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + //-------------------------------------------------------------------- |
|
| 463 | 463 | |
| 464 | 464 | |
| 465 | 465 | /** |
@@ -470,109 +470,109 @@ discard block |
||
| 470 | 470 | * |
| 471 | 471 | * @return null|string |
| 472 | 472 | */ |
| 473 | - public function determine_migration_path($type, $create=false) |
|
| 474 | - { |
|
| 475 | - $type = strtolower($type); |
|
| 473 | + public function determine_migration_path($type, $create=false) |
|
| 474 | + { |
|
| 475 | + $type = strtolower($type); |
|
| 476 | 476 | |
| 477 | - // Is it a module? |
|
| 478 | - if (strpos($type, 'mod:') === 0) |
|
| 479 | - { |
|
| 480 | - $module = str_replace('mod:', '', $type); |
|
| 477 | + // Is it a module? |
|
| 478 | + if (strpos($type, 'mod:') === 0) |
|
| 479 | + { |
|
| 480 | + $module = str_replace('mod:', '', $type); |
|
| 481 | 481 | |
| 482 | - $path = \Myth\Modules::path($module, 'migrations'); |
|
| 482 | + $path = \Myth\Modules::path($module, 'migrations'); |
|
| 483 | 483 | |
| 484 | - // Should we return a 'created' module? |
|
| 485 | - // Use the first module path. |
|
| 486 | - if (empty($path) && $create === true) |
|
| 487 | - { |
|
| 484 | + // Should we return a 'created' module? |
|
| 485 | + // Use the first module path. |
|
| 486 | + if (empty($path) && $create === true) |
|
| 487 | + { |
|
| 488 | 488 | $folders = config_item('modules_locations'); |
| 489 | 489 | |
| 490 | - if (is_array($folders) && count($folders)) |
|
| 491 | - { |
|
| 492 | - $path = $folders[0] . $module .'/migrations'; |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - return rtrim($path, '/') .'/'; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - // Look in our predefined groups. |
|
| 500 | - if (! empty($this->_migration_paths[$type])) |
|
| 501 | - { |
|
| 502 | - return rtrim($this->_migration_paths[$type], '/') .'/'; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - return null; |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - //-------------------------------------------------------------------- |
|
| 509 | - |
|
| 510 | - /** |
|
| 511 | - * Returns the default migration path. This is basically the first |
|
| 512 | - * path in the migration_paths array. |
|
| 513 | - * |
|
| 514 | - * @return string |
|
| 515 | - */ |
|
| 516 | - public function default_migration_path() |
|
| 517 | - { |
|
| 518 | - return key($this->_migration_paths); |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - //-------------------------------------------------------------------- |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - //-------------------------------------------------------------------- |
|
| 525 | - // Protected Methods |
|
| 526 | - //-------------------------------------------------------------------- |
|
| 527 | - |
|
| 528 | - /** |
|
| 529 | - * Extracts the migration number from a filename |
|
| 530 | - * |
|
| 531 | - * @param string $migration |
|
| 532 | - * @return string Numeric portion of a migration filename |
|
| 533 | - */ |
|
| 534 | - protected function _get_migration_number($migration) |
|
| 535 | - { |
|
| 536 | - return sscanf($migration, '%[0-9]+', $number) |
|
| 537 | - ? $number : '0'; |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - // -------------------------------------------------------------------- |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * Extracts the migration class name from a filename |
|
| 544 | - * |
|
| 545 | - * @param string $migration |
|
| 546 | - * @return string text portion of a migration filename |
|
| 547 | - */ |
|
| 548 | - protected function _get_migration_name($migration) |
|
| 549 | - { |
|
| 550 | - $parts = explode('_', $migration); |
|
| 551 | - array_shift($parts); |
|
| 552 | - return implode('_', $parts); |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - // -------------------------------------------------------------------- |
|
| 556 | - |
|
| 557 | - /** |
|
| 558 | - * Stores the current schema version |
|
| 559 | - * |
|
| 560 | - * @param string $type Any key from _migration_paths, or {module_name} |
|
| 561 | - * @param string $migration Migration reached |
|
| 562 | - * @return mixed Outputs a report of the migration |
|
| 563 | - */ |
|
| 564 | - protected function _update_version($type='all', $migration) |
|
| 565 | - { |
|
| 566 | - $this->db->where('alias', $type) |
|
| 567 | - ->delete($this->_migration_table); |
|
| 568 | - |
|
| 569 | - return $this->db->insert($this->_migration_table, array( |
|
| 570 | - 'version' => $migration, |
|
| 571 | - 'alias' => $type, |
|
| 572 | - 'ondate' => date('Y-m-d H:i:s') |
|
| 573 | - )); |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - // -------------------------------------------------------------------- |
|
| 490 | + if (is_array($folders) && count($folders)) |
|
| 491 | + { |
|
| 492 | + $path = $folders[0] . $module .'/migrations'; |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + return rtrim($path, '/') .'/'; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + // Look in our predefined groups. |
|
| 500 | + if (! empty($this->_migration_paths[$type])) |
|
| 501 | + { |
|
| 502 | + return rtrim($this->_migration_paths[$type], '/') .'/'; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + return null; |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + //-------------------------------------------------------------------- |
|
| 509 | + |
|
| 510 | + /** |
|
| 511 | + * Returns the default migration path. This is basically the first |
|
| 512 | + * path in the migration_paths array. |
|
| 513 | + * |
|
| 514 | + * @return string |
|
| 515 | + */ |
|
| 516 | + public function default_migration_path() |
|
| 517 | + { |
|
| 518 | + return key($this->_migration_paths); |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + //-------------------------------------------------------------------- |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + //-------------------------------------------------------------------- |
|
| 525 | + // Protected Methods |
|
| 526 | + //-------------------------------------------------------------------- |
|
| 527 | + |
|
| 528 | + /** |
|
| 529 | + * Extracts the migration number from a filename |
|
| 530 | + * |
|
| 531 | + * @param string $migration |
|
| 532 | + * @return string Numeric portion of a migration filename |
|
| 533 | + */ |
|
| 534 | + protected function _get_migration_number($migration) |
|
| 535 | + { |
|
| 536 | + return sscanf($migration, '%[0-9]+', $number) |
|
| 537 | + ? $number : '0'; |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + // -------------------------------------------------------------------- |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * Extracts the migration class name from a filename |
|
| 544 | + * |
|
| 545 | + * @param string $migration |
|
| 546 | + * @return string text portion of a migration filename |
|
| 547 | + */ |
|
| 548 | + protected function _get_migration_name($migration) |
|
| 549 | + { |
|
| 550 | + $parts = explode('_', $migration); |
|
| 551 | + array_shift($parts); |
|
| 552 | + return implode('_', $parts); |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + // -------------------------------------------------------------------- |
|
| 556 | + |
|
| 557 | + /** |
|
| 558 | + * Stores the current schema version |
|
| 559 | + * |
|
| 560 | + * @param string $type Any key from _migration_paths, or {module_name} |
|
| 561 | + * @param string $migration Migration reached |
|
| 562 | + * @return mixed Outputs a report of the migration |
|
| 563 | + */ |
|
| 564 | + protected function _update_version($type='all', $migration) |
|
| 565 | + { |
|
| 566 | + $this->db->where('alias', $type) |
|
| 567 | + ->delete($this->_migration_table); |
|
| 568 | + |
|
| 569 | + return $this->db->insert($this->_migration_table, array( |
|
| 570 | + 'version' => $migration, |
|
| 571 | + 'alias' => $type, |
|
| 572 | + 'ondate' => date('Y-m-d H:i:s') |
|
| 573 | + )); |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + // -------------------------------------------------------------------- |
|
| 577 | 577 | |
| 578 | 578 | } |
@@ -2,33 +2,33 @@ |
||
| 2 | 2 | |
| 3 | 3 | class CronMailer extends \Myth\Mail\BaseMailer { |
| 4 | 4 | |
| 5 | - protected $from = null; |
|
| 6 | - protected $to = null; |
|
| 7 | - |
|
| 8 | - public function __construct() |
|
| 9 | - { |
|
| 10 | - $this->from = [ config_item('site.auth_email'), config_item('site.name') ]; |
|
| 11 | - $this->to = config_item('site.auth_email'); |
|
| 12 | - } |
|
| 13 | - |
|
| 14 | - //-------------------------------------------------------------------- |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * Sends the output from the cronjob to the admin. |
|
| 18 | - * |
|
| 19 | - * @param $output |
|
| 20 | - */ |
|
| 21 | - public function results($output=null) |
|
| 22 | - { |
|
| 23 | - $data = [ |
|
| 24 | - 'output' => $output, |
|
| 25 | - 'site_name' => config_item('site.name') |
|
| 26 | - ]; |
|
| 27 | - |
|
| 28 | - // Send it immediately - don't queue. |
|
| 29 | - return $this->send($this->to, "Cron Results from ". config_item('site.name'), $data); |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - //-------------------------------------------------------------------- |
|
| 5 | + protected $from = null; |
|
| 6 | + protected $to = null; |
|
| 7 | + |
|
| 8 | + public function __construct() |
|
| 9 | + { |
|
| 10 | + $this->from = [ config_item('site.auth_email'), config_item('site.name') ]; |
|
| 11 | + $this->to = config_item('site.auth_email'); |
|
| 12 | + } |
|
| 13 | + |
|
| 14 | + //-------------------------------------------------------------------- |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * Sends the output from the cronjob to the admin. |
|
| 18 | + * |
|
| 19 | + * @param $output |
|
| 20 | + */ |
|
| 21 | + public function results($output=null) |
|
| 22 | + { |
|
| 23 | + $data = [ |
|
| 24 | + 'output' => $output, |
|
| 25 | + 'site_name' => config_item('site.name') |
|
| 26 | + ]; |
|
| 27 | + |
|
| 28 | + // Send it immediately - don't queue. |
|
| 29 | + return $this->send($this->to, "Cron Results from ". config_item('site.name'), $data); |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + //-------------------------------------------------------------------- |
|
| 33 | 33 | |
| 34 | 34 | } |