Update20130101::update_column_password_hash()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Icybee\Modules\Users;
4
5
use ICanBoogie\Updater\AssertionFailed;
6
use ICanBoogie\Updater\Update;
7
8
/**
9
 * - Rename table `user_users` as `users`.
10
 *
11
 * @module users
12
 */
13
class Update20120101 extends Update
14
{
15
	public function update_table_users()
16
	{
17
		$db = $this->app->db;
18
19
		if (!$db->table_exists('user_users'))
20
		{
21
			throw new AssertionFailed('assert_table_exists', 'user_users');
22
		}
23
24
		if ($db->table_exists('users'))
25
		{
26
			throw new AssertionFailed('assert_not_table_exists', 'users');
27
		}
28
29
		$db("RENAME TABLE `{prefix}user_users` TO `users`");
30
	}
31
32
	public function update_constructor_type()
33
	{
34
		$db = $this->app->db;
35
		$db("UPDATE `{prefix}users` SET constructor = 'users' WHERE constructor = 'user.users'");
36
	}
37
}
38
39
/**
40
 * - Rename `password` column as `password_hash`.
41
 *
42
 * @module users
43
 */
44
class Update20130101 extends Update
45
{
46
	public function update_column_password_hash()
47
	{
48
		$this->module->model
49
		->assert_has_column('password')
50
		->rename_column('password', 'password_hash');
51
	}
52
}
53
54
/**
55
 * - Alter the column `password_hash` to suit the requirements of the Password API.
56
 * - Rename the column `created` as `created_at`.
57
 *
58
 * @module users
59
 */
60 View Code Duplication
class Update20131021 extends Update
61
{
62
	public function update_column_password_hash()
63
	{
64
		$this->module->model
65
		->assert_has_column('password_hash')
66
		->assert_not_column_has_size('password_hash', 255)
67
		->alter_column('password_hash');
68
	}
69
70
	public function update_column_created()
71
	{
72
		$this->module->model
73
		->assert_has_column('created')
74
		->rename_column('created', 'created_at');
75
	}
76
}
77
78
/**
79
 * @module users
80
 */
81 View Code Duplication
class Update20131022 extends Update
82
{
83
	/**
84
	 * Rename the column `display` as `name_as`.
85
	 */
86
	public function update_column_display()
87
	{
88
		$this->module->model
89
		->assert_has_column('display')
90
		->rename_column('display', 'name_as');
91
	}
92
93
	/**
94
	 * Create column `nickname`.
95
	 */
96
	public function update_column_nickname()
97
	{
98
		$this->module->model
99
		->assert_not_has_column('nickname')
100
		->create_column('nickname');
101
	}
102
103
	/**
104
	 * Rename column `lastconnection` as `logged_at`.
105
	 */
106
	public function update_column_lastconnection()
107
	{
108
		$this->module->model
109
		->assert_has_column('lastconnection')
110
		->rename_column('lastconnection', 'logged_at');
111
	}
112
}
113
114
115
/**
116
 * @module users
117
 */
118
class Update20150922 extends Update
119
{
120
	public function update_column_siteid()
121
	{
122
		$this->module->models['has_many_sites']
123
		->assert_has_column('siteid')
124
		->rename_column('siteid', 'site_id');
125
	}
126
}
127