|
1
|
|
|
<?php defined('BASEPATH') OR exit('No direct script access allowed'); |
|
2
|
|
|
|
|
3
|
|
|
class Migration_Setup_Notices extends CI_Migration { |
|
4
|
|
|
public function __construct() { |
|
5
|
|
|
parent::__construct(); |
|
|
|
|
|
|
6
|
|
|
$this->load->dbforge(); |
|
7
|
|
|
} |
|
8
|
|
|
|
|
9
|
|
|
public function up() { |
|
10
|
|
|
//Notice table |
|
11
|
|
|
$this->dbforge->add_field(array( |
|
12
|
|
|
'id' => array( |
|
13
|
|
|
'type' => 'MEDIUMINT', |
|
14
|
|
|
'constraint' => '8', |
|
15
|
|
|
'unsigned' => TRUE, |
|
16
|
|
|
'auto_increment' => TRUE |
|
17
|
|
|
), |
|
18
|
|
|
'notice' => array( |
|
19
|
|
|
'type' => 'VARCHAR', |
|
20
|
|
|
'constraint' => '255' |
|
21
|
|
|
//FOREIGN KEY |
|
22
|
|
|
), |
|
23
|
|
|
'created_at' => array( |
|
24
|
|
|
//Despite not actually creating the field here (it's instead done below), we still need this here so a key can be created properly. |
|
25
|
|
|
// 'type' => 'TIMESTAMP', |
|
26
|
|
|
// 'null' => FALSE, |
|
27
|
|
|
// 'on_update' => FALSE |
|
28
|
|
|
) |
|
29
|
|
|
)); |
|
30
|
|
|
$this->dbforge->add_field('created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP'); //CI is annoying and auto-appends ON UPDATE which we don't want. |
|
|
|
|
|
|
31
|
|
|
$this->dbforge->add_key('id', TRUE); |
|
32
|
|
|
$this->dbforge->add_key('created_at'); |
|
33
|
|
|
$this->dbforge->create_table('tracker_notices'); |
|
34
|
|
|
|
|
35
|
|
|
//User notice hidden table |
|
36
|
|
|
$this->dbforge->add_field(array( |
|
37
|
|
|
'user_id' => array( |
|
38
|
|
|
'type' => 'MEDIUMINT', |
|
39
|
|
|
'constraint' => '8', |
|
40
|
|
|
'unsigned' => TRUE, |
|
41
|
|
|
//FOREIGN KEY |
|
42
|
|
|
), |
|
43
|
|
|
'hidden_notice_id' => array( |
|
44
|
|
|
'type' => 'MEDIUMINT', |
|
45
|
|
|
'constraint' => '8', |
|
46
|
|
|
'unsigned' => TRUE |
|
47
|
|
|
//FOREIGN KEY |
|
48
|
|
|
) |
|
49
|
|
|
)); |
|
50
|
|
|
$this->dbforge->add_key('user_id', TRUE); |
|
51
|
|
|
$this->dbforge->create_table('tracker_user_notices'); |
|
52
|
|
|
|
|
53
|
|
|
/*** Unique/Foreign Keys ***/ |
|
54
|
|
|
//For whatever reason, dbforge lacks a unique/foreign key function. |
|
55
|
|
|
$this->db->query(' |
|
56
|
|
|
ALTER TABLE `tracker_user_notices` |
|
57
|
|
|
ADD CONSTRAINT `FK_tracker_user_notices_auth_users` FOREIGN KEY (`user_id`) REFERENCES `auth_users`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION, |
|
58
|
|
|
ADD CONSTRAINT `FK_tracker_user_notices_tracker_notices` FOREIGN KEY (`hidden_notice_id`) REFERENCES `tracker_notices` (`id`) ON UPDATE NO ACTION ON DELETE NO ACTION;' |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function down() { |
|
63
|
|
|
$this->dbforge->drop_table('tracker_notices', TRUE); |
|
64
|
|
|
$this->dbforge->drop_table('tracker_user_notices', TRUE); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: