Completed
Push — master ( 9d2e77...ac0adf )
by Charles
02:45
created
protected/messages/en_us/models/email.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -1,28 +1,28 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Message translations.
4
- *
5
- * This file is automatically generated by 'yiic message' command.
6
- * It contains the localizable messages extracted from source code.
7
- * You may modify this file by translating the extracted messages.
8
- *
9
- * Each array element represents the translation (value) of a message (key).
10
- * If the value is empty, the message is considered as not translated.
11
- * Messages that no longer need translation will have their translations
12
- * enclosed between a pair of '@@' marks.
13
- *
14
- * Message string can be used with plural forms format. Check i18n section
15
- * of the guide for details.
16
- *
17
- * NOTE, this file must be saved in UTF-8 encoding.
18
- */
3
+     * Message translations.
4
+     *
5
+     * This file is automatically generated by 'yiic message' command.
6
+     * It contains the localizable messages extracted from source code.
7
+     * You may modify this file by translating the extracted messages.
8
+     *
9
+     * Each array element represents the translation (value) of a message (key).
10
+     * If the value is empty, the message is considered as not translated.
11
+     * Messages that no longer need translation will have their translations
12
+     * enclosed between a pair of '@@' marks.
13
+     *
14
+     * Message string can be used with plural forms format. Check i18n section
15
+     * of the guide for details.
16
+     *
17
+     * NOTE, this file must be saved in UTF-8 encoding.
18
+     */
19 19
 return array (
20
-  'SMTP Hostname' => '',
21
-  'SMTP Password' => '',
22
-  'SMTP Port Number' => '',
23
-  'SMTP Username' => '',
24
-  'System Email Address' => '',
25
-  'System From Name' => '',
26
-  'Use SSL Connection' => '',
27
-  'Use TLS Connection' => '',
20
+    'SMTP Hostname' => '',
21
+    'SMTP Password' => '',
22
+    'SMTP Port Number' => '',
23
+    'SMTP Username' => '',
24
+    'System Email Address' => '',
25
+    'System From Name' => '',
26
+    'Use SSL Connection' => '',
27
+    'Use TLS Connection' => '',
28 28
 );
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
  *
17 17
  * NOTE, this file must be saved in UTF-8 encoding.
18 18
  */
19
-return array (
19
+return array(
20 20
   '&lt; Previous' => '',
21 21
   '&lt;&lt; First' => '',
22 22
   'CApcCache requires PHP apc extension to be loaded.' => '',
Please login to merge, or discard this patch.
protected/messages/en_us/models/general.php 2 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -1,46 +1,46 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Message translations.
4
- *
5
- * This file is automatically generated by 'yiic ciimessage' command.
6
- * It contains the localizable messages extracted from source code.
7
- * You may modify this file by translating the extracted messages.
8
- *
9
- * Each array element represents the translation (value) of a message (key).
10
- * If the value is empty, the message is considered as not translated.
11
- * Messages that no longer need translation will have their translations
12
- * enclosed between a pair of '@@' marks.
13
- *
14
- * Message string can be used with plural forms format. Check i18n section
15
- * of the guide for details.
16
- *
17
- * NOTE, this file must be saved in UTF-8 encoding.
18
- */
3
+     * Message translations.
4
+     *
5
+     * This file is automatically generated by 'yiic ciimessage' command.
6
+     * It contains the localizable messages extracted from source code.
7
+     * You may modify this file by translating the extracted messages.
8
+     *
9
+     * Each array element represents the translation (value) of a message (key).
10
+     * If the value is empty, the message is considered as not translated.
11
+     * Messages that no longer need translation will have their translations
12
+     * enclosed between a pair of '@@' marks.
13
+     *
14
+     * Message string can be used with plural forms format. Check i18n section
15
+     * of the guide for details.
16
+     *
17
+     * NOTE, this file must be saved in UTF-8 encoding.
18
+     */
19 19
 return array (
20
-  'Category Post Count' => '',
21
-  'Content Post Cost' => '',
22
-  'Date Format' => '',
23
-  'Default Language' => '',
24
-  'Discourse' => '',
25
-  'Discourse URL' => '',
26
-  'Display Settings' => '',
27
-  'Disqus' => '',
28
-  'Disqus Shortcode' => '',
29
-  'Force SSL for Secure Areas' => '',
30
-  'Offline Mode' => '',
31
-  'Openstack API Key' => '',
32
-  'Openstack Container Name' => '',
33
-  'Openstack Identity URL' => '',
34
-  'Openstack Region' => '',
35
-  'Openstack Username' => '',
36
-  'Password Strength Settings' => '',
37
-  'Search Post Count' => '',
38
-  'Site Name' => '',
39
-  'Site Settings' => '',
40
-  'Time Format' => '',
41
-  'Upload Settings' => '',
42
-  'Use Discourse Comments' => '',
43
-  'Use Disqus Comments' => '',
44
-  'Use Openstack for Uploads?' => '',
45
-  'Use Rackspace CDN?' => '',
20
+    'Category Post Count' => '',
21
+    'Content Post Cost' => '',
22
+    'Date Format' => '',
23
+    'Default Language' => '',
24
+    'Discourse' => '',
25
+    'Discourse URL' => '',
26
+    'Display Settings' => '',
27
+    'Disqus' => '',
28
+    'Disqus Shortcode' => '',
29
+    'Force SSL for Secure Areas' => '',
30
+    'Offline Mode' => '',
31
+    'Openstack API Key' => '',
32
+    'Openstack Container Name' => '',
33
+    'Openstack Identity URL' => '',
34
+    'Openstack Region' => '',
35
+    'Openstack Username' => '',
36
+    'Password Strength Settings' => '',
37
+    'Search Post Count' => '',
38
+    'Site Name' => '',
39
+    'Site Settings' => '',
40
+    'Time Format' => '',
41
+    'Upload Settings' => '',
42
+    'Use Discourse Comments' => '',
43
+    'Use Disqus Comments' => '',
44
+    'Use Openstack for Uploads?' => '',
45
+    'Use Rackspace CDN?' => '',
46 46
 );
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
  *
17 17
  * NOTE, this file must be saved in UTF-8 encoding.
18 18
  */
19
-return array (
19
+return array(
20 20
   '&lt; Previous' => '',
21 21
   '&lt;&lt; First' => '',
22 22
   'CApcCache requires PHP apc extension to be loaded.' => '',
Please login to merge, or discard this patch.
protected/messages/en_us/models/social.php 2 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -1,37 +1,37 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Message translations.
4
- *
5
- * This file is automatically generated by 'yiic message' command.
6
- * It contains the localizable messages extracted from source code.
7
- * You may modify this file by translating the extracted messages.
8
- *
9
- * Each array element represents the translation (value) of a message (key).
10
- * If the value is empty, the message is considered as not translated.
11
- * Messages that no longer need translation will have their translations
12
- * enclosed between a pair of '@@' marks.
13
- *
14
- * Message string can be used with plural forms format. Check i18n section
15
- * of the guide for details.
16
- *
17
- * NOTE, this file must be saved in UTF-8 encoding.
18
- */
3
+     * Message translations.
4
+     *
5
+     * This file is automatically generated by 'yiic message' command.
6
+     * It contains the localizable messages extracted from source code.
7
+     * You may modify this file by translating the extracted messages.
8
+     *
9
+     * Each array element represents the translation (value) of a message (key).
10
+     * If the value is empty, the message is considered as not translated.
11
+     * Messages that no longer need translation will have their translations
12
+     * enclosed between a pair of '@@' marks.
13
+     *
14
+     * Message string can be used with plural forms format. Check i18n section
15
+     * of the guide for details.
16
+     *
17
+     * NOTE, this file must be saved in UTF-8 encoding.
18
+     */
19 19
 return array (
20
-  'Access Token' => '',
21
-  'Access Token Secret' => '',
22
-  'AddThis' => '',
23
-  'AddThis Publisher ID' => '',
24
-  'App ID' => '',
25
-  'App Secret' => '',
26
-  'Client ID' => '',
27
-  'Client Secret' => '',
28
-  'Consumer Key' => '',
29
-  'Consumer Secret' => '',
30
-  'Facebook' => '',
31
-  'Google+' => '',
32
-  'LinkedIn' => '',
33
-  'Public Server API Key' => '',
34
-  'Scope' => '',
35
-  'Social Auth' => '',
36
-  'Twitter' => '',
20
+    'Access Token' => '',
21
+    'Access Token Secret' => '',
22
+    'AddThis' => '',
23
+    'AddThis Publisher ID' => '',
24
+    'App ID' => '',
25
+    'App Secret' => '',
26
+    'Client ID' => '',
27
+    'Client Secret' => '',
28
+    'Consumer Key' => '',
29
+    'Consumer Secret' => '',
30
+    'Facebook' => '',
31
+    'Google+' => '',
32
+    'LinkedIn' => '',
33
+    'Public Server API Key' => '',
34
+    'Scope' => '',
35
+    'Social Auth' => '',
36
+    'Twitter' => '',
37 37
 );
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
  *
17 17
  * NOTE, this file must be saved in UTF-8 encoding.
18 18
  */
19
-return array (
19
+return array(
20 20
   '&lt; Previous' => '',
21 21
   '&lt;&lt; First' => '',
22 22
   'CApcCache requires PHP apc extension to be loaded.' => '',
Please login to merge, or discard this patch.
protected/messages/en_us/models/theme.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -1,22 +1,22 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Message translations.
4
- *
5
- * This file is automatically generated by 'yiic ciimessage' command.
6
- * It contains the localizable messages extracted from source code.
7
- * You may modify this file by translating the extracted messages.
8
- *
9
- * Each array element represents the translation (value) of a message (key).
10
- * If the value is empty, the message is considered as not translated.
11
- * Messages that no longer need translation will have their translations
12
- * enclosed between a pair of '@@' marks.
13
- *
14
- * Message string can be used with plural forms format. Check i18n section
15
- * of the guide for details.
16
- *
17
- * NOTE, this file must be saved in UTF-8 encoding.
18
- */
3
+     * Message translations.
4
+     *
5
+     * This file is automatically generated by 'yiic ciimessage' command.
6
+     * It contains the localizable messages extracted from source code.
7
+     * You may modify this file by translating the extracted messages.
8
+     *
9
+     * Each array element represents the translation (value) of a message (key).
10
+     * If the value is empty, the message is considered as not translated.
11
+     * Messages that no longer need translation will have their translations
12
+     * enclosed between a pair of '@@' marks.
13
+     *
14
+     * Message string can be used with plural forms format. Check i18n section
15
+     * of the guide for details.
16
+     *
17
+     * NOTE, this file must be saved in UTF-8 encoding.
18
+     */
19 19
 return array (
20
-  'All Posts' => '',
21
-  'Theme' => '',
20
+    'All Posts' => '',
21
+    'Theme' => '',
22 22
 );
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
  *
17 17
  * NOTE, this file must be saved in UTF-8 encoding.
18 18
  */
19
-return array (
19
+return array(
20 20
   '&lt; Previous' => '',
21 21
   '&lt;&lt; First' => '',
22 22
   'CApcCache requires PHP apc extension to be loaded.' => '',
Please login to merge, or discard this patch.
protected/messages/en_us/module/Dashboard/main.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -1,23 +1,23 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Message translations.
4
- *
5
- * This file is automatically generated by 'yiic message' command.
6
- * It contains the localizable messages extracted from source code.
7
- * You may modify this file by translating the extracted messages.
8
- *
9
- * Each array element represents the translation (value) of a message (key).
10
- * If the value is empty, the message is considered as not translated.
11
- * Messages that no longer need translation will have their translations
12
- * enclosed between a pair of '@@' marks.
13
- *
14
- * Message string can be used with plural forms format. Check i18n section
15
- * of the guide for details.
16
- *
17
- * NOTE, this file must be saved in UTF-8 encoding.
18
- */
3
+     * Message translations.
4
+     *
5
+     * This file is automatically generated by 'yiic message' command.
6
+     * It contains the localizable messages extracted from source code.
7
+     * You may modify this file by translating the extracted messages.
8
+     *
9
+     * Each array element represents the translation (value) of a message (key).
10
+     * If the value is empty, the message is considered as not translated.
11
+     * Messages that no longer need translation will have their translations
12
+     * enclosed between a pair of '@@' marks.
13
+     *
14
+     * Message string can be used with plural forms format. Check i18n section
15
+     * of the guide for details.
16
+     *
17
+     * NOTE, this file must be saved in UTF-8 encoding.
18
+     */
19 19
 return array (
20
-  'Change Theme Settings' => '',
21
-  'There are no settings for this section.' => '',
22
-  'Unable to save uploaded image.' => '',
20
+    'Change Theme Settings' => '',
21
+    'There are no settings for this section.' => '',
22
+    'Unable to save uploaded image.' => '',
23 23
 );
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
  *
17 17
  * NOTE, this file must be saved in UTF-8 encoding.
18 18
  */
19
-return array (
19
+return array(
20 20
   '&lt; Previous' => '',
21 21
   '&lt;&lt; First' => '',
22 22
   'CApcCache requires PHP apc extension to be loaded.' => '',
Please login to merge, or discard this patch.
protected/messages/en_us/yii.php 2 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -1,30 +1,30 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Message translations.
4
- *
5
- * This file is automatically generated by 'yiic message' command.
6
- * It contains the localizable messages extracted from source code.
7
- * You may modify this file by translating the extracted messages.
8
- *
9
- * Each array element represents the translation (value) of a message (key).
10
- * If the value is empty, the message is considered as not translated.
11
- * Messages that no longer need translation will have their translations
12
- * enclosed between a pair of '@@' marks.
13
- *
14
- * Message string can be used with plural forms format. Check i18n section
15
- * of the guide for details.
16
- *
17
- * NOTE, this file must be saved in UTF-8 encoding.
18
- */
3
+     * Message translations.
4
+     *
5
+     * This file is automatically generated by 'yiic message' command.
6
+     * It contains the localizable messages extracted from source code.
7
+     * You may modify this file by translating the extracted messages.
8
+     *
9
+     * Each array element represents the translation (value) of a message (key).
10
+     * If the value is empty, the message is considered as not translated.
11
+     * Messages that no longer need translation will have their translations
12
+     * enclosed between a pair of '@@' marks.
13
+     *
14
+     * Message string can be used with plural forms format. Check i18n section
15
+     * of the guide for details.
16
+     *
17
+     * NOTE, this file must be saved in UTF-8 encoding.
18
+     */
19 19
 return array (
20
-  '&lt; Previous' => '',
21
-  '&lt;&lt; First' => '',
22
-  'CApcCache requires PHP apc extension to be loaded.' => '',
23
-  'CMemCache server configuration must be an array.' => '',
24
-  'CMemCache server configuration must have "host" value.' => '',
25
-  'Go to page: ' => '',
26
-  'Last &gt;&gt;' => '',
27
-  'Next &gt;' => '',
28
-  'The "forceCopy" and "linkAssets" cannot be both true.' => '',
29
-  'The asset "{asset}" to be published does not exist.' => '',
20
+    '&lt; Previous' => '',
21
+    '&lt;&lt; First' => '',
22
+    'CApcCache requires PHP apc extension to be loaded.' => '',
23
+    'CMemCache server configuration must be an array.' => '',
24
+    'CMemCache server configuration must have "host" value.' => '',
25
+    'Go to page: ' => '',
26
+    'Last &gt;&gt;' => '',
27
+    'Next &gt;' => '',
28
+    'The "forceCopy" and "linkAssets" cannot be both true.' => '',
29
+    'The asset "{asset}" to be published does not exist.' => '',
30 30
 );
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
  *
17 17
  * NOTE, this file must be saved in UTF-8 encoding.
18 18
  */
19
-return array (
19
+return array(
20 20
   '&lt; Previous' => '',
21 21
   '&lt;&lt; First' => '',
22 22
   'CApcCache requires PHP apc extension to be loaded.' => '',
Please login to merge, or discard this patch.
protected/migrations/m141001_145619_init.php 3 patches
Indentation   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -3,286 +3,286 @@
 block discarded – undo
3 3
 class m141001_145619_init extends CDbMigration
4 4
 {
5 5
 
6
-	/**
7
-	 * For data insertions, this is the current time.
8
-	 * @var integer
9
-	 */
10
-	private $_moment = 0;
11
-
12
-	public function safeUp()
13
-	{
14
-		$this->_moment = time();
15
-
16
-		// Try to get the table names, if we get something back, do not run this migration
17
-		try
18
-		{
19
-			$test = Yii::app()->db->schema->getTables();
20
-			if (count($test) <= 1)
21
-				throw new Exception('CiiMS doesn\'t exist. Applying base migration');
22
-			return true;
23
-		}
24
-		catch (Exception $e)
25
-		{
26
-			// Yii will throw an exception if Yii::app()->db->schema is undefined (which is should be if we're doing this for the first time)
27
-			// This SHOULD throw an error if we're running this for the first time - it's the only way to check if we have a valid db or not.
28
-		}
29
-
30
-		// Otherwise, run the install migration
31
-		$this->createUserTables();
32
-
33
-		$this->createCategories();
34
-
35
-		$this->createContent();
36
-
37
-		$this->createConfiguration();
38
-	}
39
-
40
-	public function safeDown()
41
-	{
42
-		echo "m141001_145619_init does not support migration down.\n";
43
-		return false;
44
-	}
45
-
46
-	/**
47
-	 * Creates the tables, indexes, and relations for users
48
-	 */
49
-	private function createUserTables()
50
-	{
51
-		$this->createTable('users', array(
52
-			'id' 		=> 'pk',
53
-			'email' 	=> 'string NOT NULL',
54
-			'password' 	=> 'string NOT NULL',
55
-			'username'  => 'string NOT NULL',
56
-			'user_role' => 'integer DEFAULT 1',
57
-			'status' 	=> 'integer DEFAULT 1',
58
-			'created' 	=> 'integer',
59
-			'updated' 	=> 'integer'
60
-		));
61
-
62
-		$this->createTable('user_roles', array(
63
-			'id' 		=> 'pk',
64
-			'name' 		=> 'string NOT NULL',
65
-			'created' 	=> 'integer',
66
-			'updated' 	=> 'integer'
67
-		));
68
-
69
-		$this->createTable('user_metadata', array(
70
-			'user_id' 	  => 'integer',
71
-			'key'		  => 'string NOT NULL',
72
-			'value' 	  => 'text NOT NULL',
73
-			'entity_type' => 'integer',
74
-			'created' 	  => 'integer',
75
-			'updated' 	  => 'integer'
76
-		));
77
-
78
-		// Create the necessary indexes on the columns
79
-		$this->createIndex('user_email', 'users', 'email', true);
80
-		$this->createIndex('user_username', 'users', 'username', true);
81
-		$this->createIndex('user_metadata', 'user_metadata', 'user_id, key', false);
82
-
83
-		$this->addPrimaryKey('user_metadata_composite', 'user_metadata', 'user_id,key');
84
-
85
-		// Setup the foreign key constraints
86
-		$this->addForeignKey('user_roles_relation_fk', 'user_metadata', 'user_id', 'users', 'id', 'CASCADE', 'NO ACTION');
87
-
88
-		// Insert data into the tables
89
-		$this->insert('user_roles', array(
90
-			'id'      => 1,
91
-			'name' 	  => 'User',
92
-			'created' => $this->_moment,
93
-			'updated' => $this->_moment
94
-		));
95
-
96
-		$this->insert('user_roles', array(
97
-			'id'      => 2,
98
-			'name'    => 'Pending',
99
-			'created' => $this->_moment,
100
-			'updated' => $this->_moment
101
-		));
102
-
103
-		$this->insert('user_roles', array(
104
-			'id'      => 3,
105
-			'name'    => 'Suspended',
106
-			'created' => $this->_moment,
107
-			'updated' => $this->_moment
108
-		));
109
-
110
-		$this->insert('user_roles', array(
111
-			'id'      => 5,
112
-			'name'    => 'Collaborator',
113
-			'created' => $this->_moment,
114
-			'updated' => $this->_moment
115
-		));
116
-
117
-		$this->insert('user_roles', array(
118
-			'id'      => 6,
119
-			'name'    => 'Author',
120
-			'created' => $this->_moment,
121
-			'updated' => $this->_moment
122
-		));
123
-
124
-		$this->insert('user_roles', array(
125
-			'id'      => 7,
126
-			'name'    => 'User',
127
-			'created' => $this->_moment,
128
-			'updated' => $this->_moment
129
-		));
130
-
131
-		$this->insert('user_roles', array(
132
-			'id'      => 8,
133
-			'name'    => 'Publisher',
134
-			'created' => $this->_moment,
135
-			'updated' => $this->_moment
136
-		));
137
-
138
-		$this->insert('user_roles', array(
139
-			'id'      => 9,
140
-			'name'    => 'Administrator',
141
-			'created' => $this->_moment,
142
-			'updated' => $this->_moment
143
-		));
144
-	}
145
-
146
-	/**
147
-	 * Create the categories and relations
148
-	 */
149
-	private function createCategories()
150
-	{
151
-		// Categories
152
-		$this->createTable('categories', array(
153
-			'id' 		=> 'pk',
154
-			'parent_id' => 'integer DEFAULT 1',
155
-			'name' 		=> 'string NOT NULL',
156
-			'slug' 	    => 'string NOT NULL',
157
-			'created' 	=> 'integer',
158
-			'updated' 	=> 'integer'
159
-		));
160
-
161
-		$this->createTable('categories_metadata', array(
162
-			'category_id' => 'integer',
163
-			'key'		  => 'string NOT NULL',
164
-			'value' 	  => 'text NOT NULL',
165
-			'created' 	  => 'integer',
166
-			'updated' 	  => 'integer'
167
-		));
168
-
169
-		// Insert the first record into the categories table
170
-		$this->insert('categories', array(
171
-			'id'      => 1,
172
-			'name'    => 'Uncategorized',
173
-			'slug'    => 'uncategorized',
174
-			'created' => $this->_moment,
175
-			'updated' => $this->_moment
176
-		));
177
-
178
-		$this->addPrimaryKey('categories_metadata_composite', 'categories_metadata', 'category_id,key');
179
-		$this->addForeignKey('categories_parents_fk', 'categories', 'parent_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
180
-		$this->addForeignKey('categories_metadata_fk', 'categories_metadata', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
181
-	}
182
-
183
-	/**
184
-	 * Creates the content, comemnts, and necessary relations
185
-	 */
186
-	private function createContent()
187
-	{
188
-		$this->createTable('content', array(
189
-			'id'		  => 'integer NOT NULL',
190
-			'vid' 		  => 'integer NOT NULL DEFAULT 1',
191
-			'title'		  => 'string  NOT NULL',
192
-			'content'     => 'text NOT NULL',
193
-			'excerpt'     => 'text NOT NULL',
194
-			'slug'        => 'string NOT NULL',
195
-			'category_id' => 'integer DEFAULT 1',
196
-			'author_id'   => 'integer DEFAULT 1',
197
-			'type_id'     => 'integer DEFAULT 2',
198
-			'commentable' => 'integer DEFAULT 1',
199
-			'password' 	  => 'string DEFAULT NULL',
200
-			'status'      => 'integer DEFAULT 0',
201
-			'like_count'  => 'integer DEFAULT 0',
202
-			'published'	  => 'integer',
203
-			'created'     => 'integer',
204
-			'updated' 	  => 'integer'
205
-		));
206
-
207
-		$this->createTable('content_types', array(
208
-			'id'          => 'pk',
209
-			'name'		  => 'string NOT NULL',
210
-			'created'     => 'integer',
211
-			'updated' 	  => 'integer'
212
-		));
213
-
214
-		$this->createTable('content_metadata', array(
215
-			'content_id'  => 'integer',
216
-			'key'		  => 'string NOT NULL',
217
-			'value' 	  => 'text NOT NULL',
218
-			'created' 	  => 'integer',
219
-			'updated' 	  => 'integer'
220
-		));
221
-
222
-		$this->createTable('comments', array(
223
-			'id'		  => 'pk',
224
-			'content_id'  => 'integer',
225
-			'author_id'   => 'integer',
226
-			'comment'     => 'integer',
227
-			'created'     => 'integer',
228
-			'updated' 	  => 'integer'
229
-		));
230
-
231
-		$this->insert('content_types', array(
232
-			'id'          => 1,
233
-			'name'        => 'Static Page',
234
-			'created'     => $this->_moment,
235
-			'updated'     => $this->_moment
236
-		));
237
-
238
-		$this->insert('content_types', array(
239
-			'id'          => 2,
240
-			'name'    	  => 'Blog Post',
241
-			'created'     => $this->_moment,
242
-			'updated'     => $this->_moment
243
-		));
244
-
245
-		$this->addPrimaryKey('content_composite', 'content', 'id, vid');
246
-
247
-		$this->execute('ALTER TABLE `content` CHANGE id id INT( 11 ) NOT NULL AUTO_INCREMENT');
248
-
249
-		$this->addPrimaryKey('content_metadata_composite', 'content_metadata', 'content_id,key');
250
-
251
-		$this->createIndex('content_author', 'content', 'author_id', false);
252
-		$this->createIndex('content_category', 'content', 'category_id', false);
253
-		$this->createIndex('content_type', 'content', 'type_id', false);
254
-		$this->createIndex('comment_content', 'comments', 'content_id', false);
255
-		$this->createIndex('comment_author', 'comments', 'author_id', false);
256
-
257
-		$this->addForeignKey('content_category_fk', 'content', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
258
-		$this->addForeignKey('content_author_fk', 'content', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION');
259
-		$this->addForeignKey('content_type_fk', 'content', 'type_id', 'content_types', 'id', 'CASCADE', 'NO ACTION');
260
-
261
-		$this->addForeignKey('comments_content_id_fk', 'comments', 'content_id', 'content', 'id', 'CASCADE', 'NO ACTION');
262
-		$this->addForeignKey('comments_author_fk', 'comments', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION');
263
-	}
264
-
265
-	/**
266
-	 * Creates the configuration and events tables
267
-	 */
268
-	private function createConfiguration()
269
-	{
270
-		$this->createTable('configuration', array(
271
-			'key'		  => 'string',
272
-			'value' 	  => 'text NOT NULL',
273
-			'created' 	  => 'integer',
274
-			'updated' 	  => 'integer'
275
-		));
276
-
277
-		$this->createTable('events', array(
278
-			'id'		  => 'pk',
279
-			'event'       => 'string NOT NULL',
280
-			'event_data'  => 'text DEFAULT NULL',
281
-			'uri'         => 'string DEFAULT NULL',
282
-			'content_id'  => 'integer DEFAULT NULL',
283
-			'created' 	  => 'integer'
284
-		));
285
-
286
-		$this->addPrimaryKey('configuration_pk', 'configuration', 'key');
287
-	}
6
+    /**
7
+     * For data insertions, this is the current time.
8
+     * @var integer
9
+     */
10
+    private $_moment = 0;
11
+
12
+    public function safeUp()
13
+    {
14
+        $this->_moment = time();
15
+
16
+        // Try to get the table names, if we get something back, do not run this migration
17
+        try
18
+        {
19
+            $test = Yii::app()->db->schema->getTables();
20
+            if (count($test) <= 1)
21
+                throw new Exception('CiiMS doesn\'t exist. Applying base migration');
22
+            return true;
23
+        }
24
+        catch (Exception $e)
25
+        {
26
+            // Yii will throw an exception if Yii::app()->db->schema is undefined (which is should be if we're doing this for the first time)
27
+            // This SHOULD throw an error if we're running this for the first time - it's the only way to check if we have a valid db or not.
28
+        }
29
+
30
+        // Otherwise, run the install migration
31
+        $this->createUserTables();
32
+
33
+        $this->createCategories();
34
+
35
+        $this->createContent();
36
+
37
+        $this->createConfiguration();
38
+    }
39
+
40
+    public function safeDown()
41
+    {
42
+        echo "m141001_145619_init does not support migration down.\n";
43
+        return false;
44
+    }
45
+
46
+    /**
47
+     * Creates the tables, indexes, and relations for users
48
+     */
49
+    private function createUserTables()
50
+    {
51
+        $this->createTable('users', array(
52
+            'id' 		=> 'pk',
53
+            'email' 	=> 'string NOT NULL',
54
+            'password' 	=> 'string NOT NULL',
55
+            'username'  => 'string NOT NULL',
56
+            'user_role' => 'integer DEFAULT 1',
57
+            'status' 	=> 'integer DEFAULT 1',
58
+            'created' 	=> 'integer',
59
+            'updated' 	=> 'integer'
60
+        ));
61
+
62
+        $this->createTable('user_roles', array(
63
+            'id' 		=> 'pk',
64
+            'name' 		=> 'string NOT NULL',
65
+            'created' 	=> 'integer',
66
+            'updated' 	=> 'integer'
67
+        ));
68
+
69
+        $this->createTable('user_metadata', array(
70
+            'user_id' 	  => 'integer',
71
+            'key'		  => 'string NOT NULL',
72
+            'value' 	  => 'text NOT NULL',
73
+            'entity_type' => 'integer',
74
+            'created' 	  => 'integer',
75
+            'updated' 	  => 'integer'
76
+        ));
77
+
78
+        // Create the necessary indexes on the columns
79
+        $this->createIndex('user_email', 'users', 'email', true);
80
+        $this->createIndex('user_username', 'users', 'username', true);
81
+        $this->createIndex('user_metadata', 'user_metadata', 'user_id, key', false);
82
+
83
+        $this->addPrimaryKey('user_metadata_composite', 'user_metadata', 'user_id,key');
84
+
85
+        // Setup the foreign key constraints
86
+        $this->addForeignKey('user_roles_relation_fk', 'user_metadata', 'user_id', 'users', 'id', 'CASCADE', 'NO ACTION');
87
+
88
+        // Insert data into the tables
89
+        $this->insert('user_roles', array(
90
+            'id'      => 1,
91
+            'name' 	  => 'User',
92
+            'created' => $this->_moment,
93
+            'updated' => $this->_moment
94
+        ));
95
+
96
+        $this->insert('user_roles', array(
97
+            'id'      => 2,
98
+            'name'    => 'Pending',
99
+            'created' => $this->_moment,
100
+            'updated' => $this->_moment
101
+        ));
102
+
103
+        $this->insert('user_roles', array(
104
+            'id'      => 3,
105
+            'name'    => 'Suspended',
106
+            'created' => $this->_moment,
107
+            'updated' => $this->_moment
108
+        ));
109
+
110
+        $this->insert('user_roles', array(
111
+            'id'      => 5,
112
+            'name'    => 'Collaborator',
113
+            'created' => $this->_moment,
114
+            'updated' => $this->_moment
115
+        ));
116
+
117
+        $this->insert('user_roles', array(
118
+            'id'      => 6,
119
+            'name'    => 'Author',
120
+            'created' => $this->_moment,
121
+            'updated' => $this->_moment
122
+        ));
123
+
124
+        $this->insert('user_roles', array(
125
+            'id'      => 7,
126
+            'name'    => 'User',
127
+            'created' => $this->_moment,
128
+            'updated' => $this->_moment
129
+        ));
130
+
131
+        $this->insert('user_roles', array(
132
+            'id'      => 8,
133
+            'name'    => 'Publisher',
134
+            'created' => $this->_moment,
135
+            'updated' => $this->_moment
136
+        ));
137
+
138
+        $this->insert('user_roles', array(
139
+            'id'      => 9,
140
+            'name'    => 'Administrator',
141
+            'created' => $this->_moment,
142
+            'updated' => $this->_moment
143
+        ));
144
+    }
145
+
146
+    /**
147
+     * Create the categories and relations
148
+     */
149
+    private function createCategories()
150
+    {
151
+        // Categories
152
+        $this->createTable('categories', array(
153
+            'id' 		=> 'pk',
154
+            'parent_id' => 'integer DEFAULT 1',
155
+            'name' 		=> 'string NOT NULL',
156
+            'slug' 	    => 'string NOT NULL',
157
+            'created' 	=> 'integer',
158
+            'updated' 	=> 'integer'
159
+        ));
160
+
161
+        $this->createTable('categories_metadata', array(
162
+            'category_id' => 'integer',
163
+            'key'		  => 'string NOT NULL',
164
+            'value' 	  => 'text NOT NULL',
165
+            'created' 	  => 'integer',
166
+            'updated' 	  => 'integer'
167
+        ));
168
+
169
+        // Insert the first record into the categories table
170
+        $this->insert('categories', array(
171
+            'id'      => 1,
172
+            'name'    => 'Uncategorized',
173
+            'slug'    => 'uncategorized',
174
+            'created' => $this->_moment,
175
+            'updated' => $this->_moment
176
+        ));
177
+
178
+        $this->addPrimaryKey('categories_metadata_composite', 'categories_metadata', 'category_id,key');
179
+        $this->addForeignKey('categories_parents_fk', 'categories', 'parent_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
180
+        $this->addForeignKey('categories_metadata_fk', 'categories_metadata', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
181
+    }
182
+
183
+    /**
184
+     * Creates the content, comemnts, and necessary relations
185
+     */
186
+    private function createContent()
187
+    {
188
+        $this->createTable('content', array(
189
+            'id'		  => 'integer NOT NULL',
190
+            'vid' 		  => 'integer NOT NULL DEFAULT 1',
191
+            'title'		  => 'string  NOT NULL',
192
+            'content'     => 'text NOT NULL',
193
+            'excerpt'     => 'text NOT NULL',
194
+            'slug'        => 'string NOT NULL',
195
+            'category_id' => 'integer DEFAULT 1',
196
+            'author_id'   => 'integer DEFAULT 1',
197
+            'type_id'     => 'integer DEFAULT 2',
198
+            'commentable' => 'integer DEFAULT 1',
199
+            'password' 	  => 'string DEFAULT NULL',
200
+            'status'      => 'integer DEFAULT 0',
201
+            'like_count'  => 'integer DEFAULT 0',
202
+            'published'	  => 'integer',
203
+            'created'     => 'integer',
204
+            'updated' 	  => 'integer'
205
+        ));
206
+
207
+        $this->createTable('content_types', array(
208
+            'id'          => 'pk',
209
+            'name'		  => 'string NOT NULL',
210
+            'created'     => 'integer',
211
+            'updated' 	  => 'integer'
212
+        ));
213
+
214
+        $this->createTable('content_metadata', array(
215
+            'content_id'  => 'integer',
216
+            'key'		  => 'string NOT NULL',
217
+            'value' 	  => 'text NOT NULL',
218
+            'created' 	  => 'integer',
219
+            'updated' 	  => 'integer'
220
+        ));
221
+
222
+        $this->createTable('comments', array(
223
+            'id'		  => 'pk',
224
+            'content_id'  => 'integer',
225
+            'author_id'   => 'integer',
226
+            'comment'     => 'integer',
227
+            'created'     => 'integer',
228
+            'updated' 	  => 'integer'
229
+        ));
230
+
231
+        $this->insert('content_types', array(
232
+            'id'          => 1,
233
+            'name'        => 'Static Page',
234
+            'created'     => $this->_moment,
235
+            'updated'     => $this->_moment
236
+        ));
237
+
238
+        $this->insert('content_types', array(
239
+            'id'          => 2,
240
+            'name'    	  => 'Blog Post',
241
+            'created'     => $this->_moment,
242
+            'updated'     => $this->_moment
243
+        ));
244
+
245
+        $this->addPrimaryKey('content_composite', 'content', 'id, vid');
246
+
247
+        $this->execute('ALTER TABLE `content` CHANGE id id INT( 11 ) NOT NULL AUTO_INCREMENT');
248
+
249
+        $this->addPrimaryKey('content_metadata_composite', 'content_metadata', 'content_id,key');
250
+
251
+        $this->createIndex('content_author', 'content', 'author_id', false);
252
+        $this->createIndex('content_category', 'content', 'category_id', false);
253
+        $this->createIndex('content_type', 'content', 'type_id', false);
254
+        $this->createIndex('comment_content', 'comments', 'content_id', false);
255
+        $this->createIndex('comment_author', 'comments', 'author_id', false);
256
+
257
+        $this->addForeignKey('content_category_fk', 'content', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
258
+        $this->addForeignKey('content_author_fk', 'content', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION');
259
+        $this->addForeignKey('content_type_fk', 'content', 'type_id', 'content_types', 'id', 'CASCADE', 'NO ACTION');
260
+
261
+        $this->addForeignKey('comments_content_id_fk', 'comments', 'content_id', 'content', 'id', 'CASCADE', 'NO ACTION');
262
+        $this->addForeignKey('comments_author_fk', 'comments', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION');
263
+    }
264
+
265
+    /**
266
+     * Creates the configuration and events tables
267
+     */
268
+    private function createConfiguration()
269
+    {
270
+        $this->createTable('configuration', array(
271
+            'key'		  => 'string',
272
+            'value' 	  => 'text NOT NULL',
273
+            'created' 	  => 'integer',
274
+            'updated' 	  => 'integer'
275
+        ));
276
+
277
+        $this->createTable('events', array(
278
+            'id'		  => 'pk',
279
+            'event'       => 'string NOT NULL',
280
+            'event_data'  => 'text DEFAULT NULL',
281
+            'uri'         => 'string DEFAULT NULL',
282
+            'content_id'  => 'integer DEFAULT NULL',
283
+            'created' 	  => 'integer'
284
+        ));
285
+
286
+        $this->addPrimaryKey('configuration_pk', 'configuration', 'key');
287
+    }
288 288
 }
289 289
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -9,16 +9,16 @@  discard block
 block discarded – undo
9 9
 	 */
10 10
 	private $_moment = 0;
11 11
 
12
-	public function safeUp()
12
+	public function safeUp ()
13 13
 	{
14
-		$this->_moment = time();
14
+		$this->_moment = time ();
15 15
 
16 16
 		// Try to get the table names, if we get something back, do not run this migration
17 17
 		try
18 18
 		{
19
-			$test = Yii::app()->db->schema->getTables();
20
-			if (count($test) <= 1)
21
-				throw new Exception('CiiMS doesn\'t exist. Applying base migration');
19
+			$test = Yii::app ()->db->schema->getTables ();
20
+			if (count ($test) <= 1)
21
+				throw new Exception ('CiiMS doesn\'t exist. Applying base migration');
22 22
 			return true;
23 23
 		}
24 24
 		catch (Exception $e)
@@ -28,16 +28,16 @@  discard block
 block discarded – undo
28 28
 		}
29 29
 
30 30
 		// Otherwise, run the install migration
31
-		$this->createUserTables();
31
+		$this->createUserTables ();
32 32
 
33
-		$this->createCategories();
33
+		$this->createCategories ();
34 34
 
35
-		$this->createContent();
35
+		$this->createContent ();
36 36
 
37
-		$this->createConfiguration();
37
+		$this->createConfiguration ();
38 38
 	}
39 39
 
40
-	public function safeDown()
40
+	public function safeDown ()
41 41
 	{
42 42
 		echo "m141001_145619_init does not support migration down.\n";
43 43
 		return false;
@@ -46,9 +46,9 @@  discard block
 block discarded – undo
46 46
 	/**
47 47
 	 * Creates the tables, indexes, and relations for users
48 48
 	 */
49
-	private function createUserTables()
49
+	private function createUserTables ()
50 50
 	{
51
-		$this->createTable('users', array(
51
+		$this->createTable ('users', array(
52 52
 			'id' 		=> 'pk',
53 53
 			'email' 	=> 'string NOT NULL',
54 54
 			'password' 	=> 'string NOT NULL',
@@ -59,14 +59,14 @@  discard block
 block discarded – undo
59 59
 			'updated' 	=> 'integer'
60 60
 		));
61 61
 
62
-		$this->createTable('user_roles', array(
62
+		$this->createTable ('user_roles', array(
63 63
 			'id' 		=> 'pk',
64 64
 			'name' 		=> 'string NOT NULL',
65 65
 			'created' 	=> 'integer',
66 66
 			'updated' 	=> 'integer'
67 67
 		));
68 68
 
69
-		$this->createTable('user_metadata', array(
69
+		$this->createTable ('user_metadata', array(
70 70
 			'user_id' 	  => 'integer',
71 71
 			'key'		  => 'string NOT NULL',
72 72
 			'value' 	  => 'text NOT NULL',
@@ -76,66 +76,66 @@  discard block
 block discarded – undo
76 76
 		));
77 77
 
78 78
 		// Create the necessary indexes on the columns
79
-		$this->createIndex('user_email', 'users', 'email', true);
80
-		$this->createIndex('user_username', 'users', 'username', true);
81
-		$this->createIndex('user_metadata', 'user_metadata', 'user_id, key', false);
79
+		$this->createIndex ('user_email', 'users', 'email', true);
80
+		$this->createIndex ('user_username', 'users', 'username', true);
81
+		$this->createIndex ('user_metadata', 'user_metadata', 'user_id, key', false);
82 82
 
83
-		$this->addPrimaryKey('user_metadata_composite', 'user_metadata', 'user_id,key');
83
+		$this->addPrimaryKey ('user_metadata_composite', 'user_metadata', 'user_id,key');
84 84
 
85 85
 		// Setup the foreign key constraints
86
-		$this->addForeignKey('user_roles_relation_fk', 'user_metadata', 'user_id', 'users', 'id', 'CASCADE', 'NO ACTION');
86
+		$this->addForeignKey ('user_roles_relation_fk', 'user_metadata', 'user_id', 'users', 'id', 'CASCADE', 'NO ACTION');
87 87
 
88 88
 		// Insert data into the tables
89
-		$this->insert('user_roles', array(
89
+		$this->insert ('user_roles', array(
90 90
 			'id'      => 1,
91 91
 			'name' 	  => 'User',
92 92
 			'created' => $this->_moment,
93 93
 			'updated' => $this->_moment
94 94
 		));
95 95
 
96
-		$this->insert('user_roles', array(
96
+		$this->insert ('user_roles', array(
97 97
 			'id'      => 2,
98 98
 			'name'    => 'Pending',
99 99
 			'created' => $this->_moment,
100 100
 			'updated' => $this->_moment
101 101
 		));
102 102
 
103
-		$this->insert('user_roles', array(
103
+		$this->insert ('user_roles', array(
104 104
 			'id'      => 3,
105 105
 			'name'    => 'Suspended',
106 106
 			'created' => $this->_moment,
107 107
 			'updated' => $this->_moment
108 108
 		));
109 109
 
110
-		$this->insert('user_roles', array(
110
+		$this->insert ('user_roles', array(
111 111
 			'id'      => 5,
112 112
 			'name'    => 'Collaborator',
113 113
 			'created' => $this->_moment,
114 114
 			'updated' => $this->_moment
115 115
 		));
116 116
 
117
-		$this->insert('user_roles', array(
117
+		$this->insert ('user_roles', array(
118 118
 			'id'      => 6,
119 119
 			'name'    => 'Author',
120 120
 			'created' => $this->_moment,
121 121
 			'updated' => $this->_moment
122 122
 		));
123 123
 
124
-		$this->insert('user_roles', array(
124
+		$this->insert ('user_roles', array(
125 125
 			'id'      => 7,
126 126
 			'name'    => 'User',
127 127
 			'created' => $this->_moment,
128 128
 			'updated' => $this->_moment
129 129
 		));
130 130
 
131
-		$this->insert('user_roles', array(
131
+		$this->insert ('user_roles', array(
132 132
 			'id'      => 8,
133 133
 			'name'    => 'Publisher',
134 134
 			'created' => $this->_moment,
135 135
 			'updated' => $this->_moment
136 136
 		));
137 137
 
138
-		$this->insert('user_roles', array(
138
+		$this->insert ('user_roles', array(
139 139
 			'id'      => 9,
140 140
 			'name'    => 'Administrator',
141 141
 			'created' => $this->_moment,
@@ -146,10 +146,10 @@  discard block
 block discarded – undo
146 146
 	/**
147 147
 	 * Create the categories and relations
148 148
 	 */
149
-	private function createCategories()
149
+	private function createCategories ()
150 150
 	{
151 151
 		// Categories
152
-		$this->createTable('categories', array(
152
+		$this->createTable ('categories', array(
153 153
 			'id' 		=> 'pk',
154 154
 			'parent_id' => 'integer DEFAULT 1',
155 155
 			'name' 		=> 'string NOT NULL',
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 			'updated' 	=> 'integer'
159 159
 		));
160 160
 
161
-		$this->createTable('categories_metadata', array(
161
+		$this->createTable ('categories_metadata', array(
162 162
 			'category_id' => 'integer',
163 163
 			'key'		  => 'string NOT NULL',
164 164
 			'value' 	  => 'text NOT NULL',
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 		));
168 168
 
169 169
 		// Insert the first record into the categories table
170
-		$this->insert('categories', array(
170
+		$this->insert ('categories', array(
171 171
 			'id'      => 1,
172 172
 			'name'    => 'Uncategorized',
173 173
 			'slug'    => 'uncategorized',
@@ -175,17 +175,17 @@  discard block
 block discarded – undo
175 175
 			'updated' => $this->_moment
176 176
 		));
177 177
 
178
-		$this->addPrimaryKey('categories_metadata_composite', 'categories_metadata', 'category_id,key');
179
-		$this->addForeignKey('categories_parents_fk', 'categories', 'parent_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
180
-		$this->addForeignKey('categories_metadata_fk', 'categories_metadata', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
178
+		$this->addPrimaryKey ('categories_metadata_composite', 'categories_metadata', 'category_id,key');
179
+		$this->addForeignKey ('categories_parents_fk', 'categories', 'parent_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
180
+		$this->addForeignKey ('categories_metadata_fk', 'categories_metadata', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
181 181
 	}
182 182
 
183 183
 	/**
184 184
 	 * Creates the content, comemnts, and necessary relations
185 185
 	 */
186
-	private function createContent()
186
+	private function createContent ()
187 187
 	{
188
-		$this->createTable('content', array(
188
+		$this->createTable ('content', array(
189 189
 			'id'		  => 'integer NOT NULL',
190 190
 			'vid' 		  => 'integer NOT NULL DEFAULT 1',
191 191
 			'title'		  => 'string  NOT NULL',
@@ -204,14 +204,14 @@  discard block
 block discarded – undo
204 204
 			'updated' 	  => 'integer'
205 205
 		));
206 206
 
207
-		$this->createTable('content_types', array(
207
+		$this->createTable ('content_types', array(
208 208
 			'id'          => 'pk',
209 209
 			'name'		  => 'string NOT NULL',
210 210
 			'created'     => 'integer',
211 211
 			'updated' 	  => 'integer'
212 212
 		));
213 213
 
214
-		$this->createTable('content_metadata', array(
214
+		$this->createTable ('content_metadata', array(
215 215
 			'content_id'  => 'integer',
216 216
 			'key'		  => 'string NOT NULL',
217 217
 			'value' 	  => 'text NOT NULL',
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 			'updated' 	  => 'integer'
220 220
 		));
221 221
 
222
-		$this->createTable('comments', array(
222
+		$this->createTable ('comments', array(
223 223
 			'id'		  => 'pk',
224 224
 			'content_id'  => 'integer',
225 225
 			'author_id'   => 'integer',
@@ -228,53 +228,53 @@  discard block
 block discarded – undo
228 228
 			'updated' 	  => 'integer'
229 229
 		));
230 230
 
231
-		$this->insert('content_types', array(
231
+		$this->insert ('content_types', array(
232 232
 			'id'          => 1,
233 233
 			'name'        => 'Static Page',
234 234
 			'created'     => $this->_moment,
235 235
 			'updated'     => $this->_moment
236 236
 		));
237 237
 
238
-		$this->insert('content_types', array(
238
+		$this->insert ('content_types', array(
239 239
 			'id'          => 2,
240 240
 			'name'    	  => 'Blog Post',
241 241
 			'created'     => $this->_moment,
242 242
 			'updated'     => $this->_moment
243 243
 		));
244 244
 
245
-		$this->addPrimaryKey('content_composite', 'content', 'id, vid');
245
+		$this->addPrimaryKey ('content_composite', 'content', 'id, vid');
246 246
 
247
-		$this->execute('ALTER TABLE `content` CHANGE id id INT( 11 ) NOT NULL AUTO_INCREMENT');
247
+		$this->execute ('ALTER TABLE `content` CHANGE id id INT( 11 ) NOT NULL AUTO_INCREMENT');
248 248
 
249
-		$this->addPrimaryKey('content_metadata_composite', 'content_metadata', 'content_id,key');
249
+		$this->addPrimaryKey ('content_metadata_composite', 'content_metadata', 'content_id,key');
250 250
 
251
-		$this->createIndex('content_author', 'content', 'author_id', false);
252
-		$this->createIndex('content_category', 'content', 'category_id', false);
253
-		$this->createIndex('content_type', 'content', 'type_id', false);
254
-		$this->createIndex('comment_content', 'comments', 'content_id', false);
255
-		$this->createIndex('comment_author', 'comments', 'author_id', false);
251
+		$this->createIndex ('content_author', 'content', 'author_id', false);
252
+		$this->createIndex ('content_category', 'content', 'category_id', false);
253
+		$this->createIndex ('content_type', 'content', 'type_id', false);
254
+		$this->createIndex ('comment_content', 'comments', 'content_id', false);
255
+		$this->createIndex ('comment_author', 'comments', 'author_id', false);
256 256
 
257
-		$this->addForeignKey('content_category_fk', 'content', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
258
-		$this->addForeignKey('content_author_fk', 'content', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION');
259
-		$this->addForeignKey('content_type_fk', 'content', 'type_id', 'content_types', 'id', 'CASCADE', 'NO ACTION');
257
+		$this->addForeignKey ('content_category_fk', 'content', 'category_id', 'categories', 'id', 'CASCADE', 'NO ACTION');
258
+		$this->addForeignKey ('content_author_fk', 'content', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION');
259
+		$this->addForeignKey ('content_type_fk', 'content', 'type_id', 'content_types', 'id', 'CASCADE', 'NO ACTION');
260 260
 
261
-		$this->addForeignKey('comments_content_id_fk', 'comments', 'content_id', 'content', 'id', 'CASCADE', 'NO ACTION');
262
-		$this->addForeignKey('comments_author_fk', 'comments', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION');
261
+		$this->addForeignKey ('comments_content_id_fk', 'comments', 'content_id', 'content', 'id', 'CASCADE', 'NO ACTION');
262
+		$this->addForeignKey ('comments_author_fk', 'comments', 'author_id', 'users', 'id', 'CASCADE', 'NO ACTION');
263 263
 	}
264 264
 
265 265
 	/**
266 266
 	 * Creates the configuration and events tables
267 267
 	 */
268
-	private function createConfiguration()
268
+	private function createConfiguration ()
269 269
 	{
270
-		$this->createTable('configuration', array(
270
+		$this->createTable ('configuration', array(
271 271
 			'key'		  => 'string',
272 272
 			'value' 	  => 'text NOT NULL',
273 273
 			'created' 	  => 'integer',
274 274
 			'updated' 	  => 'integer'
275 275
 		));
276 276
 
277
-		$this->createTable('events', array(
277
+		$this->createTable ('events', array(
278 278
 			'id'		  => 'pk',
279 279
 			'event'       => 'string NOT NULL',
280 280
 			'event_data'  => 'text DEFAULT NULL',
@@ -283,6 +283,6 @@  discard block
 block discarded – undo
283 283
 			'created' 	  => 'integer'
284 284
 		));
285 285
 
286
-		$this->addPrimaryKey('configuration_pk', 'configuration', 'key');
286
+		$this->addPrimaryKey ('configuration_pk', 'configuration', 'key');
287 287
 	}
288 288
 }
289 289
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -17,11 +17,11 @@
 block discarded – undo
17 17
 		try
18 18
 		{
19 19
 			$test = Yii::app()->db->schema->getTables();
20
-			if (count($test) <= 1)
21
-				throw new Exception('CiiMS doesn\'t exist. Applying base migration');
20
+			if (count($test) <= 1) {
21
+							throw new Exception('CiiMS doesn\'t exist. Applying base migration');
22
+			}
22 23
 			return true;
23
-		}
24
-		catch (Exception $e)
24
+		} catch (Exception $e)
25 25
 		{
26 26
 			// Yii will throw an exception if Yii::app()->db->schema is undefined (which is should be if we're doing this for the first time)
27 27
 			// This SHOULD throw an error if we're running this for the first time - it's the only way to check if we have a valid db or not.
Please login to merge, or discard this patch.
protected/models/Categories.php 3 patches
Indentation   +315 added lines, -315 removed lines patch added patch discarded remove patch
@@ -19,319 +19,319 @@
 block discarded – undo
19 19
  */
20 20
 class Categories extends CiiModel
21 21
 {
22
-	public $pageSize = 15;
23
-
24
-	public $description = NULL;
25
-
26
-	public $keywords = array();
27
-
28
-	/**
29
-	 * Returns the static model of the specified AR class.
30
-	 * @param string $className active record class name.
31
-	 * @return Categories the static model class
32
-	 */
33
-	public static function model($className=__CLASS__)
34
-	{
35
-		return parent::model($className);
36
-	}
37
-
38
-	/**
39
-	 * @return string the associated database table name
40
-	 */
41
-	public function tableName()
42
-	{
43
-		return 'categories';
44
-	}
45
-
46
-	/**
47
-	 * @return array validation rules for model attributes.
48
-	 */
49
-	public function rules()
50
-	{
51
-		// NOTE: you should only define rules for those attributes that
52
-		// will receive user inputs.
53
-		return array(
54
-			array('parent_id, name', 'required'),
55
-			array('parent_id', 'numerical', 'integerOnly'=>true),
56
-			array('name, slug', 'length', 'max'=>150),
57
-			// The following rule is used by search().
58
-			// Please remove those attributes that should not be searched.
59
-			array('id, parent_id, name, slug', 'safe', 'on'=>'search'),
60
-		);
61
-	}
62
-
63
-	/**
64
-	 * @return array relational rules.
65
-	 */
66
-	public function relations()
67
-	{
68
-		// NOTE: you may need to adjust the relation name and the related
69
-		// class name for the relations automatically generated below.
70
-		return array(
71
-			'parent' => array(self::BELONGS_TO, 'Categories', 'parent_id'),
72
-			'metadata' => array(self::HAS_MANY, 'CategoriesMetadata', 'category_id'),
73
-			'content' => array(self::HAS_MANY, 'Content', 'category_id'),
74
-		);
75
-	}
76
-
77
-	/**
78
-	 * @return array customized attribute labels (name=>label)
79
-	 */
80
-	public function attributeLabels()
81
-	{
82
-		return array(
83
-			'id' 		=> Yii::t('ciims.models.Categories', 'ID'),
84
-			'parent_id' => Yii::t('ciims.models.Categories', 'Parent'),
85
-			'name'      => Yii::t('ciims.models.Categories', 'Name'),
86
-			'slug'      => Yii::t('ciims.models.Categories', 'Slug'),
87
-			'description' => Yii::t('ciims.models.Categories', 'Description'),
88
-			'created'   => Yii::t('ciims.models.Categories', 'Created'),
89
-			'updated'   => Yii::t('ciims.models.Categories', 'Updated'),
90
-		);
91
-	}
92
-
93
-	public function getDescription()
94
-	{
95
-		$this->description = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'description'));
96
-		if ($this->description == null || $this->description == false)
97
-			return NULL;
98
-
99
-		$this->description = $this->description->value;
100
-		return $this->description;
101
-	}
102
-
103
-	/**
104
-	 * Retrieves a list of models based on the current search/filter conditions.
105
-	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
106
-	 */
107
-	public function search()
108
-	{
109
-		$criteria=new CDbCriteria;
110
-
111
-		$criteria->compare('id',$this->id);
112
-		$criteria->compare('parent_id',$this->parent_id);
113
-		$criteria->compare('name',$this->name,true);
114
-		$criteria->compare('slug',$this->slug,true);
115
-		$criteria->compare('created',$this->created,true);
116
-		$criteria->compare('updated',$this->updated,true);
117
-		$criteria->order = "id DESC";
118
-
119
-		return new CActiveDataProvider($this, array(
120
-			'criteria' => $criteria,
121
-			'pagination' => array(
122
-				'pageSize' => $this->pageSize
123
-			)
124
-		));
125
-	}
126
-
127
-	/**
128
-	 * Gets keyword tags for this entry
129
-	 * @return array
130
-	 */
131
-	public function getKeywords()
132
-	{
133
-		$tags = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
134
-		return $tags === NULL ? array() : CJSON::decode($tags->value);
135
-	}
136
-
137
-	/**
138
-	 * Adds a tag to the model
139
-	 * @param string $tag	The tag to add
140
-	 * @return bool			If the insert was successful or not
141
-	 */
142
-	public function addKeyword($tag)
143
-	{
144
-		$tags = $this->keywords;
145
-		if (in_array($tag, $tags)  || $tag == "")
146
-			return false;
147
-
148
-		$tags[] = $tag;
149
-		$tags = CJSON::encode($tags);
150
-		$metaTag = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
151
-		if ($metaTag == false || $metaTag == NULL)
152
-		{
153
-			$metaTag = new CategoriestMetadata;
154
-			$metaTag->content_id = $this->id;
155
-			$metaTag->key = 'keywords';
156
-		}
157
-
158
-		$metaTag->value = $tags;
159
-		return $metaTag->save();
160
-	}
161
-
162
-	/**
163
-	 * Removes a tag from the model
164
-	 * @param string $tag	The tag to remove
165
-	 * @return bool			If the removal was successful
166
-	 */
167
-	public function removeKeyword($tag)
168
-	{
169
-		$tags = $this->keywords;
170
-		if (!in_array($tag, $tags) || $tag == "")
171
-			return false;
172
-
173
-		$key = array_search($tag, $tags);
174
-		unset($tags[$key]);
175
-		$tags = CJSON::encode($tags);
176
-
177
-		$metaTag = CategoryMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
178
-		$metaTag->value = $tags;
179
-		return $metaTag->save();
180
-	}
181
-
182
-	/**
183
-	 * Verifies the slug before validating the model
184
-	 */
185
-	public function beforeValidate()
186
-	{
187
-		$this->slug = $this->verifySlug($this->slug, $this->name);
188
-
189
-		return parent::beforeValidate();
190
-	}
191
-
192
-	/**
193
-	 * Flushes URL data from the cache before the model is updated
194
-	 */
195
-	public function afterSave()
196
-	{
197
-		$meta = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'description'));
198
-		if ($meta == NULL)
199
-			$meta = new CategoriesMetadata;
200
-
201
-		$meta->category_id = $this->id;
202
-		$meta->key = 'description';
203
-		$meta->value  = $this->description;
204
-
205
-		$meta->save();
206
-
207
-		Yii::app()->cache->delete('CiiMS::Content::list');
208
-		Yii::app()->cache->delete('CiiMS::Routes');
209
-		Yii::app()->cache->delete('categories-pid');
210
-
211
-		return parent::afterSave();
212
-	}
213
-
214
-	/**
215
-	 * Automatically corrects parent tree issues that arise when a parent category node
216
-	 * is deleted.
217
-	 * @return boolean
218
-	 */
219
-	public function beforeDelete()
220
-	{
221
-		// Prevents the main "uncategorized category from being deleted"
222
-		if ($this->id == 1)
223
-		{
224
-			Yii::app()->user->setFlash('error', Yii::t('ciims.models.Categories', 'This category cannot be deleted'));
225
-			return false;
226
-		}
227
-
228
-		Yii::app()->cache->delete('CiiMS::Content::list');
229
-		Yii::app()->cache->delete('CiiMS::Routes');
230
-		Yii::app()->cache->delete('categories-pid');
231
-
232
-		$parent = $this->parent_id;
233
-		$id = $this->id;
234
-
235
-		// Reassign all posts to the parent category
236
-		Yii::app()->db
237
-				->createCommand('UPDATE content SET category_id = :parent_id WHERE category_id = :id')
238
-				->bindParam(':parent_id', $parent)
239
-				->bindParam(':id', $id)
240
-				->execute();
241
-
242
-		// Reassign all child categories to the parent category
243
-		$data = $this->findAllByAttributes(array('parent_id' => $id));
244
-
245
-		foreach ($data as $row)
246
-		{
247
-			$id = $row->id;
248
-			Yii::app()->db
249
-					->createCommand('UPDATE categories SET parent_id = :parent_id WHERE id = :id')
250
-					->bindParam(':parent_id', $parent)
251
-					->bindParam(':id', $id)
252
-					->execute();
253
-		}
254
-
255
-		return parent::beforeDelete();
256
-	}
257
-
258
-	/**
259
-	 * Retrieves the parent categories for a given category_id
260
-	 * @param  int $id
261
-	 * @return array
262
-	 */
263
-	public function getParentCategories($id)
264
-	{
265
-		// Retrieve the data from cache if necessary
266
-		$response = Yii::app()->cache->get('categories-pid');
267
-		if ($response == NULL)
268
-		{
269
-			$response = Yii::app()->db->createCommand('SELECT id, parent_id, name, slug FROM categories')->queryAll();
270
-			Yii::app()->cache->set('categories-pid', $response);
271
-		}
272
-
273
-		return $this->_getParentCategories($response, $id);
274
-	}
275
-
276
-	/**
277
-	 * Recursive callback for retrieving parent categories
278
-	 * @param  int  $id      The category we're seeking
279
-	 * @param  array  $stack A stack to hold the entire tree
280
-	 * @return array
281
-	 */
282
-	private function _getParentCategories($all_categories, $id, array $stack = array())
283
-	{
284
-		if ($id == 1)
285
-			return array_reverse($stack);
286
-
287
-		foreach ($all_categories as $k=>$v)
288
-		{
289
-			if ($v['id'] == $id)
290
-			{
291
-				$stack[$v['name']] = array(str_replace(Yii::app()->baseUrl, NULL, Yii::app()->createUrl($v['slug'])));
292
-				return $this->_getParentCategories($all_categories, $v['parent_id'], $stack);
293
-			}
294
-		}
295
-	}
296
-
297
-	/**
298
-	 * checkSlug - Recursive method to verify that the slug can be used
299
-	 * This method is purposfuly declared here to so that Content::findByPk is used instead of CiiModel::findByPk
300
-	 * @param string $slug - the slug to be checked
301
-	 * @param int $id - the numeric id to be appended to the slug if a conflict exists
302
-	 * @return string $slug - the final slug to be used
303
-	 */
304
-	public function checkSlug($slug, $id=NULL)
305
-	{
306
-		$content = false;
307
-
308
-		// Find the number of items that have the same slug as this one
309
-		$count = $this->countByAttributes(array('slug'=>$slug . $id));
310
-
311
-		if ($count == 0)
312
-		{
313
-			$content = true;
314
-			$count = Content::model()->countByAttributes(array('slug'=>$slug . $id));
315
-		}
316
-
317
-		// If we found an item that matched, it's possible that it is the current item (or a previous version of it)
318
-		// in which case we don't need to alter the slug
319
-		if ($count >= 1)
320
-		{
321
-			if ($content)
322
-				return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
323
-
324
-			// Pull the data that matches
325
-			$data = $this->findByPk($this->id === NULL ? -1 : $this->id);
326
-
327
-			// Check the pulled data id to the current item
328
-			if ($data !== NULL && $data->id == $this->id)
329
-				return $slug;
330
-		}
331
-
332
-		if ($count == 0 && !in_array($slug, $this->forbiddenRoutes))
333
-			return $slug . $id;
334
-		else
335
-			return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
336
-	}
22
+    public $pageSize = 15;
23
+
24
+    public $description = NULL;
25
+
26
+    public $keywords = array();
27
+
28
+    /**
29
+     * Returns the static model of the specified AR class.
30
+     * @param string $className active record class name.
31
+     * @return Categories the static model class
32
+     */
33
+    public static function model($className=__CLASS__)
34
+    {
35
+        return parent::model($className);
36
+    }
37
+
38
+    /**
39
+     * @return string the associated database table name
40
+     */
41
+    public function tableName()
42
+    {
43
+        return 'categories';
44
+    }
45
+
46
+    /**
47
+     * @return array validation rules for model attributes.
48
+     */
49
+    public function rules()
50
+    {
51
+        // NOTE: you should only define rules for those attributes that
52
+        // will receive user inputs.
53
+        return array(
54
+            array('parent_id, name', 'required'),
55
+            array('parent_id', 'numerical', 'integerOnly'=>true),
56
+            array('name, slug', 'length', 'max'=>150),
57
+            // The following rule is used by search().
58
+            // Please remove those attributes that should not be searched.
59
+            array('id, parent_id, name, slug', 'safe', 'on'=>'search'),
60
+        );
61
+    }
62
+
63
+    /**
64
+     * @return array relational rules.
65
+     */
66
+    public function relations()
67
+    {
68
+        // NOTE: you may need to adjust the relation name and the related
69
+        // class name for the relations automatically generated below.
70
+        return array(
71
+            'parent' => array(self::BELONGS_TO, 'Categories', 'parent_id'),
72
+            'metadata' => array(self::HAS_MANY, 'CategoriesMetadata', 'category_id'),
73
+            'content' => array(self::HAS_MANY, 'Content', 'category_id'),
74
+        );
75
+    }
76
+
77
+    /**
78
+     * @return array customized attribute labels (name=>label)
79
+     */
80
+    public function attributeLabels()
81
+    {
82
+        return array(
83
+            'id' 		=> Yii::t('ciims.models.Categories', 'ID'),
84
+            'parent_id' => Yii::t('ciims.models.Categories', 'Parent'),
85
+            'name'      => Yii::t('ciims.models.Categories', 'Name'),
86
+            'slug'      => Yii::t('ciims.models.Categories', 'Slug'),
87
+            'description' => Yii::t('ciims.models.Categories', 'Description'),
88
+            'created'   => Yii::t('ciims.models.Categories', 'Created'),
89
+            'updated'   => Yii::t('ciims.models.Categories', 'Updated'),
90
+        );
91
+    }
92
+
93
+    public function getDescription()
94
+    {
95
+        $this->description = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'description'));
96
+        if ($this->description == null || $this->description == false)
97
+            return NULL;
98
+
99
+        $this->description = $this->description->value;
100
+        return $this->description;
101
+    }
102
+
103
+    /**
104
+     * Retrieves a list of models based on the current search/filter conditions.
105
+     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
106
+     */
107
+    public function search()
108
+    {
109
+        $criteria=new CDbCriteria;
110
+
111
+        $criteria->compare('id',$this->id);
112
+        $criteria->compare('parent_id',$this->parent_id);
113
+        $criteria->compare('name',$this->name,true);
114
+        $criteria->compare('slug',$this->slug,true);
115
+        $criteria->compare('created',$this->created,true);
116
+        $criteria->compare('updated',$this->updated,true);
117
+        $criteria->order = "id DESC";
118
+
119
+        return new CActiveDataProvider($this, array(
120
+            'criteria' => $criteria,
121
+            'pagination' => array(
122
+                'pageSize' => $this->pageSize
123
+            )
124
+        ));
125
+    }
126
+
127
+    /**
128
+     * Gets keyword tags for this entry
129
+     * @return array
130
+     */
131
+    public function getKeywords()
132
+    {
133
+        $tags = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
134
+        return $tags === NULL ? array() : CJSON::decode($tags->value);
135
+    }
136
+
137
+    /**
138
+     * Adds a tag to the model
139
+     * @param string $tag	The tag to add
140
+     * @return bool			If the insert was successful or not
141
+     */
142
+    public function addKeyword($tag)
143
+    {
144
+        $tags = $this->keywords;
145
+        if (in_array($tag, $tags)  || $tag == "")
146
+            return false;
147
+
148
+        $tags[] = $tag;
149
+        $tags = CJSON::encode($tags);
150
+        $metaTag = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
151
+        if ($metaTag == false || $metaTag == NULL)
152
+        {
153
+            $metaTag = new CategoriestMetadata;
154
+            $metaTag->content_id = $this->id;
155
+            $metaTag->key = 'keywords';
156
+        }
157
+
158
+        $metaTag->value = $tags;
159
+        return $metaTag->save();
160
+    }
161
+
162
+    /**
163
+     * Removes a tag from the model
164
+     * @param string $tag	The tag to remove
165
+     * @return bool			If the removal was successful
166
+     */
167
+    public function removeKeyword($tag)
168
+    {
169
+        $tags = $this->keywords;
170
+        if (!in_array($tag, $tags) || $tag == "")
171
+            return false;
172
+
173
+        $key = array_search($tag, $tags);
174
+        unset($tags[$key]);
175
+        $tags = CJSON::encode($tags);
176
+
177
+        $metaTag = CategoryMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
178
+        $metaTag->value = $tags;
179
+        return $metaTag->save();
180
+    }
181
+
182
+    /**
183
+     * Verifies the slug before validating the model
184
+     */
185
+    public function beforeValidate()
186
+    {
187
+        $this->slug = $this->verifySlug($this->slug, $this->name);
188
+
189
+        return parent::beforeValidate();
190
+    }
191
+
192
+    /**
193
+     * Flushes URL data from the cache before the model is updated
194
+     */
195
+    public function afterSave()
196
+    {
197
+        $meta = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'description'));
198
+        if ($meta == NULL)
199
+            $meta = new CategoriesMetadata;
200
+
201
+        $meta->category_id = $this->id;
202
+        $meta->key = 'description';
203
+        $meta->value  = $this->description;
204
+
205
+        $meta->save();
206
+
207
+        Yii::app()->cache->delete('CiiMS::Content::list');
208
+        Yii::app()->cache->delete('CiiMS::Routes');
209
+        Yii::app()->cache->delete('categories-pid');
210
+
211
+        return parent::afterSave();
212
+    }
213
+
214
+    /**
215
+     * Automatically corrects parent tree issues that arise when a parent category node
216
+     * is deleted.
217
+     * @return boolean
218
+     */
219
+    public function beforeDelete()
220
+    {
221
+        // Prevents the main "uncategorized category from being deleted"
222
+        if ($this->id == 1)
223
+        {
224
+            Yii::app()->user->setFlash('error', Yii::t('ciims.models.Categories', 'This category cannot be deleted'));
225
+            return false;
226
+        }
227
+
228
+        Yii::app()->cache->delete('CiiMS::Content::list');
229
+        Yii::app()->cache->delete('CiiMS::Routes');
230
+        Yii::app()->cache->delete('categories-pid');
231
+
232
+        $parent = $this->parent_id;
233
+        $id = $this->id;
234
+
235
+        // Reassign all posts to the parent category
236
+        Yii::app()->db
237
+                ->createCommand('UPDATE content SET category_id = :parent_id WHERE category_id = :id')
238
+                ->bindParam(':parent_id', $parent)
239
+                ->bindParam(':id', $id)
240
+                ->execute();
241
+
242
+        // Reassign all child categories to the parent category
243
+        $data = $this->findAllByAttributes(array('parent_id' => $id));
244
+
245
+        foreach ($data as $row)
246
+        {
247
+            $id = $row->id;
248
+            Yii::app()->db
249
+                    ->createCommand('UPDATE categories SET parent_id = :parent_id WHERE id = :id')
250
+                    ->bindParam(':parent_id', $parent)
251
+                    ->bindParam(':id', $id)
252
+                    ->execute();
253
+        }
254
+
255
+        return parent::beforeDelete();
256
+    }
257
+
258
+    /**
259
+     * Retrieves the parent categories for a given category_id
260
+     * @param  int $id
261
+     * @return array
262
+     */
263
+    public function getParentCategories($id)
264
+    {
265
+        // Retrieve the data from cache if necessary
266
+        $response = Yii::app()->cache->get('categories-pid');
267
+        if ($response == NULL)
268
+        {
269
+            $response = Yii::app()->db->createCommand('SELECT id, parent_id, name, slug FROM categories')->queryAll();
270
+            Yii::app()->cache->set('categories-pid', $response);
271
+        }
272
+
273
+        return $this->_getParentCategories($response, $id);
274
+    }
275
+
276
+    /**
277
+     * Recursive callback for retrieving parent categories
278
+     * @param  int  $id      The category we're seeking
279
+     * @param  array  $stack A stack to hold the entire tree
280
+     * @return array
281
+     */
282
+    private function _getParentCategories($all_categories, $id, array $stack = array())
283
+    {
284
+        if ($id == 1)
285
+            return array_reverse($stack);
286
+
287
+        foreach ($all_categories as $k=>$v)
288
+        {
289
+            if ($v['id'] == $id)
290
+            {
291
+                $stack[$v['name']] = array(str_replace(Yii::app()->baseUrl, NULL, Yii::app()->createUrl($v['slug'])));
292
+                return $this->_getParentCategories($all_categories, $v['parent_id'], $stack);
293
+            }
294
+        }
295
+    }
296
+
297
+    /**
298
+     * checkSlug - Recursive method to verify that the slug can be used
299
+     * This method is purposfuly declared here to so that Content::findByPk is used instead of CiiModel::findByPk
300
+     * @param string $slug - the slug to be checked
301
+     * @param int $id - the numeric id to be appended to the slug if a conflict exists
302
+     * @return string $slug - the final slug to be used
303
+     */
304
+    public function checkSlug($slug, $id=NULL)
305
+    {
306
+        $content = false;
307
+
308
+        // Find the number of items that have the same slug as this one
309
+        $count = $this->countByAttributes(array('slug'=>$slug . $id));
310
+
311
+        if ($count == 0)
312
+        {
313
+            $content = true;
314
+            $count = Content::model()->countByAttributes(array('slug'=>$slug . $id));
315
+        }
316
+
317
+        // If we found an item that matched, it's possible that it is the current item (or a previous version of it)
318
+        // in which case we don't need to alter the slug
319
+        if ($count >= 1)
320
+        {
321
+            if ($content)
322
+                return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
323
+
324
+            // Pull the data that matches
325
+            $data = $this->findByPk($this->id === NULL ? -1 : $this->id);
326
+
327
+            // Check the pulled data id to the current item
328
+            if ($data !== NULL && $data->id == $this->id)
329
+                return $slug;
330
+        }
331
+
332
+        if ($count == 0 && !in_array($slug, $this->forbiddenRoutes))
333
+            return $slug . $id;
334
+        else
335
+            return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
336
+    }
337 337
 }
Please login to merge, or discard this patch.
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -30,15 +30,15 @@  discard block
 block discarded – undo
30 30
 	 * @param string $className active record class name.
31 31
 	 * @return Categories the static model class
32 32
 	 */
33
-	public static function model($className=__CLASS__)
33
+	public static function model ($className = __CLASS__)
34 34
 	{
35
-		return parent::model($className);
35
+		return parent::model ($className);
36 36
 	}
37 37
 
38 38
 	/**
39 39
 	 * @return string the associated database table name
40 40
 	 */
41
-	public function tableName()
41
+	public function tableName ()
42 42
 	{
43 43
 		return 'categories';
44 44
 	}
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	/**
47 47
 	 * @return array validation rules for model attributes.
48 48
 	 */
49
-	public function rules()
49
+	public function rules ()
50 50
 	{
51 51
 		// NOTE: you should only define rules for those attributes that
52 52
 		// will receive user inputs.
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	/**
64 64
 	 * @return array relational rules.
65 65
 	 */
66
-	public function relations()
66
+	public function relations ()
67 67
 	{
68 68
 		// NOTE: you may need to adjust the relation name and the related
69 69
 		// class name for the relations automatically generated below.
@@ -77,22 +77,22 @@  discard block
 block discarded – undo
77 77
 	/**
78 78
 	 * @return array customized attribute labels (name=>label)
79 79
 	 */
80
-	public function attributeLabels()
80
+	public function attributeLabels ()
81 81
 	{
82 82
 		return array(
83
-			'id' 		=> Yii::t('ciims.models.Categories', 'ID'),
84
-			'parent_id' => Yii::t('ciims.models.Categories', 'Parent'),
85
-			'name'      => Yii::t('ciims.models.Categories', 'Name'),
86
-			'slug'      => Yii::t('ciims.models.Categories', 'Slug'),
87
-			'description' => Yii::t('ciims.models.Categories', 'Description'),
88
-			'created'   => Yii::t('ciims.models.Categories', 'Created'),
89
-			'updated'   => Yii::t('ciims.models.Categories', 'Updated'),
83
+			'id' 		=> Yii::t ('ciims.models.Categories', 'ID'),
84
+			'parent_id' => Yii::t ('ciims.models.Categories', 'Parent'),
85
+			'name'      => Yii::t ('ciims.models.Categories', 'Name'),
86
+			'slug'      => Yii::t ('ciims.models.Categories', 'Slug'),
87
+			'description' => Yii::t ('ciims.models.Categories', 'Description'),
88
+			'created'   => Yii::t ('ciims.models.Categories', 'Created'),
89
+			'updated'   => Yii::t ('ciims.models.Categories', 'Updated'),
90 90
 		);
91 91
 	}
92 92
 
93
-	public function getDescription()
93
+	public function getDescription ()
94 94
 	{
95
-		$this->description = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'description'));
95
+		$this->description = CategoriesMetadata::model ()->findByAttributes (array('category_id' => $this->id, 'key' => 'description'));
96 96
 		if ($this->description == null || $this->description == false)
97 97
 			return NULL;
98 98
 
@@ -104,19 +104,19 @@  discard block
 block discarded – undo
104 104
 	 * Retrieves a list of models based on the current search/filter conditions.
105 105
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
106 106
 	 */
107
-	public function search()
107
+	public function search ()
108 108
 	{
109
-		$criteria=new CDbCriteria;
110
-
111
-		$criteria->compare('id',$this->id);
112
-		$criteria->compare('parent_id',$this->parent_id);
113
-		$criteria->compare('name',$this->name,true);
114
-		$criteria->compare('slug',$this->slug,true);
115
-		$criteria->compare('created',$this->created,true);
116
-		$criteria->compare('updated',$this->updated,true);
109
+		$criteria = new CDbCriteria;
110
+
111
+		$criteria->compare ('id', $this->id);
112
+		$criteria->compare ('parent_id', $this->parent_id);
113
+		$criteria->compare ('name', $this->name, true);
114
+		$criteria->compare ('slug', $this->slug, true);
115
+		$criteria->compare ('created', $this->created, true);
116
+		$criteria->compare ('updated', $this->updated, true);
117 117
 		$criteria->order = "id DESC";
118 118
 
119
-		return new CActiveDataProvider($this, array(
119
+		return new CActiveDataProvider ($this, array(
120 120
 			'criteria' => $criteria,
121 121
 			'pagination' => array(
122 122
 				'pageSize' => $this->pageSize
@@ -128,10 +128,10 @@  discard block
 block discarded – undo
128 128
 	 * Gets keyword tags for this entry
129 129
 	 * @return array
130 130
 	 */
131
-	public function getKeywords()
131
+	public function getKeywords ()
132 132
 	{
133
-		$tags = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
134
-		return $tags === NULL ? array() : CJSON::decode($tags->value);
133
+		$tags = CategoriesMetadata::model ()->findByAttributes (array('category_id' => $this->id, 'key' => 'keywords'));
134
+		return $tags === NULL ? array() : CJSON::decode ($tags->value);
135 135
 	}
136 136
 
137 137
 	/**
@@ -139,15 +139,15 @@  discard block
 block discarded – undo
139 139
 	 * @param string $tag	The tag to add
140 140
 	 * @return bool			If the insert was successful or not
141 141
 	 */
142
-	public function addKeyword($tag)
142
+	public function addKeyword ($tag)
143 143
 	{
144 144
 		$tags = $this->keywords;
145
-		if (in_array($tag, $tags)  || $tag == "")
145
+		if (in_array ($tag, $tags) || $tag == "")
146 146
 			return false;
147 147
 
148 148
 		$tags[] = $tag;
149
-		$tags = CJSON::encode($tags);
150
-		$metaTag = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
149
+		$tags = CJSON::encode ($tags);
150
+		$metaTag = CategoriesMetadata::model ()->findByAttributes (array('category_id' => $this->id, 'key' => 'keywords'));
151 151
 		if ($metaTag == false || $metaTag == NULL)
152 152
 		{
153 153
 			$metaTag = new CategoriestMetadata;
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 		}
157 157
 
158 158
 		$metaTag->value = $tags;
159
-		return $metaTag->save();
159
+		return $metaTag->save ();
160 160
 	}
161 161
 
162 162
 	/**
@@ -164,51 +164,51 @@  discard block
 block discarded – undo
164 164
 	 * @param string $tag	The tag to remove
165 165
 	 * @return bool			If the removal was successful
166 166
 	 */
167
-	public function removeKeyword($tag)
167
+	public function removeKeyword ($tag)
168 168
 	{
169 169
 		$tags = $this->keywords;
170
-		if (!in_array($tag, $tags) || $tag == "")
170
+		if (!in_array ($tag, $tags) || $tag == "")
171 171
 			return false;
172 172
 
173
-		$key = array_search($tag, $tags);
173
+		$key = array_search ($tag, $tags);
174 174
 		unset($tags[$key]);
175
-		$tags = CJSON::encode($tags);
175
+		$tags = CJSON::encode ($tags);
176 176
 
177
-		$metaTag = CategoryMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
177
+		$metaTag = CategoryMetadata::model ()->findByAttributes (array('category_id' => $this->id, 'key' => 'keywords'));
178 178
 		$metaTag->value = $tags;
179
-		return $metaTag->save();
179
+		return $metaTag->save ();
180 180
 	}
181 181
 
182 182
 	/**
183 183
 	 * Verifies the slug before validating the model
184 184
 	 */
185
-	public function beforeValidate()
185
+	public function beforeValidate ()
186 186
 	{
187
-		$this->slug = $this->verifySlug($this->slug, $this->name);
187
+		$this->slug = $this->verifySlug ($this->slug, $this->name);
188 188
 
189
-		return parent::beforeValidate();
189
+		return parent::beforeValidate ();
190 190
 	}
191 191
 
192 192
 	/**
193 193
 	 * Flushes URL data from the cache before the model is updated
194 194
 	 */
195
-	public function afterSave()
195
+	public function afterSave ()
196 196
 	{
197
-		$meta = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'description'));
197
+		$meta = CategoriesMetadata::model ()->findByAttributes (array('category_id' => $this->id, 'key' => 'description'));
198 198
 		if ($meta == NULL)
199 199
 			$meta = new CategoriesMetadata;
200 200
 
201 201
 		$meta->category_id = $this->id;
202 202
 		$meta->key = 'description';
203
-		$meta->value  = $this->description;
203
+		$meta->value = $this->description;
204 204
 
205
-		$meta->save();
205
+		$meta->save ();
206 206
 
207
-		Yii::app()->cache->delete('CiiMS::Content::list');
208
-		Yii::app()->cache->delete('CiiMS::Routes');
209
-		Yii::app()->cache->delete('categories-pid');
207
+		Yii::app ()->cache->delete ('CiiMS::Content::list');
208
+		Yii::app ()->cache->delete ('CiiMS::Routes');
209
+		Yii::app ()->cache->delete ('categories-pid');
210 210
 
211
-		return parent::afterSave();
211
+		return parent::afterSave ();
212 212
 	}
213 213
 
214 214
 	/**
@@ -216,43 +216,43 @@  discard block
 block discarded – undo
216 216
 	 * is deleted.
217 217
 	 * @return boolean
218 218
 	 */
219
-	public function beforeDelete()
219
+	public function beforeDelete ()
220 220
 	{
221 221
 		// Prevents the main "uncategorized category from being deleted"
222 222
 		if ($this->id == 1)
223 223
 		{
224
-			Yii::app()->user->setFlash('error', Yii::t('ciims.models.Categories', 'This category cannot be deleted'));
224
+			Yii::app ()->user->setFlash ('error', Yii::t ('ciims.models.Categories', 'This category cannot be deleted'));
225 225
 			return false;
226 226
 		}
227 227
 
228
-		Yii::app()->cache->delete('CiiMS::Content::list');
229
-		Yii::app()->cache->delete('CiiMS::Routes');
230
-		Yii::app()->cache->delete('categories-pid');
228
+		Yii::app ()->cache->delete ('CiiMS::Content::list');
229
+		Yii::app ()->cache->delete ('CiiMS::Routes');
230
+		Yii::app ()->cache->delete ('categories-pid');
231 231
 
232 232
 		$parent = $this->parent_id;
233 233
 		$id = $this->id;
234 234
 
235 235
 		// Reassign all posts to the parent category
236
-		Yii::app()->db
237
-				->createCommand('UPDATE content SET category_id = :parent_id WHERE category_id = :id')
238
-				->bindParam(':parent_id', $parent)
239
-				->bindParam(':id', $id)
240
-				->execute();
236
+		Yii::app ()->db
237
+				->createCommand ('UPDATE content SET category_id = :parent_id WHERE category_id = :id')
238
+				->bindParam (':parent_id', $parent)
239
+				->bindParam (':id', $id)
240
+				->execute ();
241 241
 
242 242
 		// Reassign all child categories to the parent category
243
-		$data = $this->findAllByAttributes(array('parent_id' => $id));
243
+		$data = $this->findAllByAttributes (array('parent_id' => $id));
244 244
 
245 245
 		foreach ($data as $row)
246 246
 		{
247 247
 			$id = $row->id;
248
-			Yii::app()->db
249
-					->createCommand('UPDATE categories SET parent_id = :parent_id WHERE id = :id')
250
-					->bindParam(':parent_id', $parent)
251
-					->bindParam(':id', $id)
252
-					->execute();
248
+			Yii::app ()->db
249
+					->createCommand ('UPDATE categories SET parent_id = :parent_id WHERE id = :id')
250
+					->bindParam (':parent_id', $parent)
251
+					->bindParam (':id', $id)
252
+					->execute ();
253 253
 		}
254 254
 
255
-		return parent::beforeDelete();
255
+		return parent::beforeDelete ();
256 256
 	}
257 257
 
258 258
 	/**
@@ -260,17 +260,17 @@  discard block
 block discarded – undo
260 260
 	 * @param  int $id
261 261
 	 * @return array
262 262
 	 */
263
-	public function getParentCategories($id)
263
+	public function getParentCategories ($id)
264 264
 	{
265 265
 		// Retrieve the data from cache if necessary
266
-		$response = Yii::app()->cache->get('categories-pid');
266
+		$response = Yii::app ()->cache->get ('categories-pid');
267 267
 		if ($response == NULL)
268 268
 		{
269
-			$response = Yii::app()->db->createCommand('SELECT id, parent_id, name, slug FROM categories')->queryAll();
270
-			Yii::app()->cache->set('categories-pid', $response);
269
+			$response = Yii::app ()->db->createCommand ('SELECT id, parent_id, name, slug FROM categories')->queryAll ();
270
+			Yii::app ()->cache->set ('categories-pid', $response);
271 271
 		}
272 272
 
273
-		return $this->_getParentCategories($response, $id);
273
+		return $this->_getParentCategories ($response, $id);
274 274
 	}
275 275
 
276 276
 	/**
@@ -279,17 +279,17 @@  discard block
 block discarded – undo
279 279
 	 * @param  array  $stack A stack to hold the entire tree
280 280
 	 * @return array
281 281
 	 */
282
-	private function _getParentCategories($all_categories, $id, array $stack = array())
282
+	private function _getParentCategories ($all_categories, $id, array $stack = array())
283 283
 	{
284 284
 		if ($id == 1)
285
-			return array_reverse($stack);
285
+			return array_reverse ($stack);
286 286
 
287 287
 		foreach ($all_categories as $k=>$v)
288 288
 		{
289 289
 			if ($v['id'] == $id)
290 290
 			{
291
-				$stack[$v['name']] = array(str_replace(Yii::app()->baseUrl, NULL, Yii::app()->createUrl($v['slug'])));
292
-				return $this->_getParentCategories($all_categories, $v['parent_id'], $stack);
291
+				$stack[$v['name']] = array(str_replace (Yii::app ()->baseUrl, NULL, Yii::app ()->createUrl ($v['slug'])));
292
+				return $this->_getParentCategories ($all_categories, $v['parent_id'], $stack);
293 293
 			}
294 294
 		}
295 295
 	}
@@ -301,17 +301,17 @@  discard block
 block discarded – undo
301 301
 	 * @param int $id - the numeric id to be appended to the slug if a conflict exists
302 302
 	 * @return string $slug - the final slug to be used
303 303
 	 */
304
-	public function checkSlug($slug, $id=NULL)
304
+	public function checkSlug ($slug, $id = NULL)
305 305
 	{
306 306
 		$content = false;
307 307
 
308 308
 		// Find the number of items that have the same slug as this one
309
-		$count = $this->countByAttributes(array('slug'=>$slug . $id));
309
+		$count = $this->countByAttributes (array('slug'=>$slug . $id));
310 310
 
311 311
 		if ($count == 0)
312 312
 		{
313 313
 			$content = true;
314
-			$count = Content::model()->countByAttributes(array('slug'=>$slug . $id));
314
+			$count = Content::model ()->countByAttributes (array('slug'=>$slug . $id));
315 315
 		}
316 316
 
317 317
 		// If we found an item that matched, it's possible that it is the current item (or a previous version of it)
@@ -319,19 +319,19 @@  discard block
 block discarded – undo
319 319
 		if ($count >= 1)
320 320
 		{
321 321
 			if ($content)
322
-				return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
322
+				return $this->checkSlug ($slug, ($id === NULL ? 1 : ($id + 1)));
323 323
 
324 324
 			// Pull the data that matches
325
-			$data = $this->findByPk($this->id === NULL ? -1 : $this->id);
325
+			$data = $this->findByPk ($this->id === NULL ? -1 : $this->id);
326 326
 
327 327
 			// Check the pulled data id to the current item
328 328
 			if ($data !== NULL && $data->id == $this->id)
329 329
 				return $slug;
330 330
 		}
331 331
 
332
-		if ($count == 0 && !in_array($slug, $this->forbiddenRoutes))
332
+		if ($count == 0 && !in_array ($slug, $this->forbiddenRoutes))
333 333
 			return $slug . $id;
334 334
 		else
335
-			return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
335
+			return $this->checkSlug ($slug, ($id === NULL ? 1 : ($id + 1)));
336 336
 	}
337 337
 }
Please login to merge, or discard this patch.
Braces   +60 added lines, -52 removed lines patch added patch discarded remove patch
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
  * @property CategoriesMetadata[] $categoriesMetadatas
18 18
  * @property Content[] $contents
19 19
  */
20
-class Categories extends CiiModel
21
-{
20
+class Categories extends CiiModel
21
+{
22 22
 	public $pageSize = 15;
23 23
 
24 24
 	public $description = NULL;
@@ -30,24 +30,24 @@  discard block
 block discarded – undo
30 30
 	 * @param string $className active record class name.
31 31
 	 * @return Categories the static model class
32 32
 	 */
33
-	public static function model($className=__CLASS__)
34
-	{
33
+	public static function model($className=__CLASS__)
34
+	{
35 35
 		return parent::model($className);
36 36
 	}
37 37
 
38 38
 	/**
39 39
 	 * @return string the associated database table name
40 40
 	 */
41
-	public function tableName()
42
-	{
41
+	public function tableName()
42
+	{
43 43
 		return 'categories';
44 44
 	}
45 45
 
46 46
 	/**
47 47
 	 * @return array validation rules for model attributes.
48 48
 	 */
49
-	public function rules()
50
-	{
49
+	public function rules()
50
+	{
51 51
 		// NOTE: you should only define rules for those attributes that
52 52
 		// will receive user inputs.
53 53
 		return array(
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 	/**
64 64
 	 * @return array relational rules.
65 65
 	 */
66
-	public function relations()
67
-	{
66
+	public function relations()
67
+	{
68 68
 		// NOTE: you may need to adjust the relation name and the related
69 69
 		// class name for the relations automatically generated below.
70 70
 		return array(
@@ -77,8 +77,8 @@  discard block
 block discarded – undo
77 77
 	/**
78 78
 	 * @return array customized attribute labels (name=>label)
79 79
 	 */
80
-	public function attributeLabels()
81
-	{
80
+	public function attributeLabels()
81
+	{
82 82
 		return array(
83 83
 			'id' 		=> Yii::t('ciims.models.Categories', 'ID'),
84 84
 			'parent_id' => Yii::t('ciims.models.Categories', 'Parent'),
@@ -90,11 +90,12 @@  discard block
 block discarded – undo
90 90
 		);
91 91
 	}
92 92
 
93
-	public function getDescription()
94
-	{
93
+	public function getDescription()
94
+	{
95 95
 		$this->description = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'description'));
96
-		if ($this->description == null || $this->description == false)
97
-			return NULL;
96
+		if ($this->description == null || $this->description == false) {
97
+					return NULL;
98
+		}
98 99
 
99 100
 		$this->description = $this->description->value;
100 101
 		return $this->description;
@@ -104,8 +105,8 @@  discard block
 block discarded – undo
104 105
 	 * Retrieves a list of models based on the current search/filter conditions.
105 106
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
106 107
 	 */
107
-	public function search()
108
-	{
108
+	public function search()
109
+	{
109 110
 		$criteria=new CDbCriteria;
110 111
 
111 112
 		$criteria->compare('id',$this->id);
@@ -128,8 +129,8 @@  discard block
 block discarded – undo
128 129
 	 * Gets keyword tags for this entry
129 130
 	 * @return array
130 131
 	 */
131
-	public function getKeywords()
132
-	{
132
+	public function getKeywords()
133
+	{
133 134
 		$tags = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
134 135
 		return $tags === NULL ? array() : CJSON::decode($tags->value);
135 136
 	}
@@ -139,11 +140,12 @@  discard block
 block discarded – undo
139 140
 	 * @param string $tag	The tag to add
140 141
 	 * @return bool			If the insert was successful or not
141 142
 	 */
142
-	public function addKeyword($tag)
143
-	{
143
+	public function addKeyword($tag)
144
+	{
144 145
 		$tags = $this->keywords;
145
-		if (in_array($tag, $tags)  || $tag == "")
146
-			return false;
146
+		if (in_array($tag, $tags)  || $tag == "") {
147
+					return false;
148
+		}
147 149
 
148 150
 		$tags[] = $tag;
149 151
 		$tags = CJSON::encode($tags);
@@ -164,11 +166,12 @@  discard block
 block discarded – undo
164 166
 	 * @param string $tag	The tag to remove
165 167
 	 * @return bool			If the removal was successful
166 168
 	 */
167
-	public function removeKeyword($tag)
168
-	{
169
+	public function removeKeyword($tag)
170
+	{
169 171
 		$tags = $this->keywords;
170
-		if (!in_array($tag, $tags) || $tag == "")
171
-			return false;
172
+		if (!in_array($tag, $tags) || $tag == "") {
173
+					return false;
174
+		}
172 175
 
173 176
 		$key = array_search($tag, $tags);
174 177
 		unset($tags[$key]);
@@ -182,8 +185,8 @@  discard block
 block discarded – undo
182 185
 	/**
183 186
 	 * Verifies the slug before validating the model
184 187
 	 */
185
-	public function beforeValidate()
186
-	{
188
+	public function beforeValidate()
189
+	{
187 190
 		$this->slug = $this->verifySlug($this->slug, $this->name);
188 191
 
189 192
 		return parent::beforeValidate();
@@ -192,11 +195,12 @@  discard block
 block discarded – undo
192 195
 	/**
193 196
 	 * Flushes URL data from the cache before the model is updated
194 197
 	 */
195
-	public function afterSave()
196
-	{
198
+	public function afterSave()
199
+	{
197 200
 		$meta = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'description'));
198
-		if ($meta == NULL)
199
-			$meta = new CategoriesMetadata;
201
+		if ($meta == NULL) {
202
+					$meta = new CategoriesMetadata;
203
+		}
200 204
 
201 205
 		$meta->category_id = $this->id;
202 206
 		$meta->key = 'description';
@@ -216,8 +220,8 @@  discard block
 block discarded – undo
216 220
 	 * is deleted.
217 221
 	 * @return boolean
218 222
 	 */
219
-	public function beforeDelete()
220
-	{
223
+	public function beforeDelete()
224
+	{
221 225
 		// Prevents the main "uncategorized category from being deleted"
222 226
 		if ($this->id == 1)
223 227
 		{
@@ -260,8 +264,8 @@  discard block
 block discarded – undo
260 264
 	 * @param  int $id
261 265
 	 * @return array
262 266
 	 */
263
-	public function getParentCategories($id)
264
-	{
267
+	public function getParentCategories($id)
268
+	{
265 269
 		// Retrieve the data from cache if necessary
266 270
 		$response = Yii::app()->cache->get('categories-pid');
267 271
 		if ($response == NULL)
@@ -279,10 +283,11 @@  discard block
 block discarded – undo
279 283
 	 * @param  array  $stack A stack to hold the entire tree
280 284
 	 * @return array
281 285
 	 */
282
-	private function _getParentCategories($all_categories, $id, array $stack = array())
283
-	{
284
-		if ($id == 1)
285
-			return array_reverse($stack);
286
+	private function _getParentCategories($all_categories, $id, array $stack = array())
287
+	{
288
+		if ($id == 1) {
289
+					return array_reverse($stack);
290
+		}
286 291
 
287 292
 		foreach ($all_categories as $k=>$v)
288 293
 		{
@@ -301,8 +306,8 @@  discard block
 block discarded – undo
301 306
 	 * @param int $id - the numeric id to be appended to the slug if a conflict exists
302 307
 	 * @return string $slug - the final slug to be used
303 308
 	 */
304
-	public function checkSlug($slug, $id=NULL)
305
-	{
309
+	public function checkSlug($slug, $id=NULL)
310
+	{
306 311
 		$content = false;
307 312
 
308 313
 		// Find the number of items that have the same slug as this one
@@ -318,20 +323,23 @@  discard block
 block discarded – undo
318 323
 		// in which case we don't need to alter the slug
319 324
 		if ($count >= 1)
320 325
 		{
321
-			if ($content)
322
-				return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
326
+			if ($content) {
327
+							return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
328
+			}
323 329
 
324 330
 			// Pull the data that matches
325 331
 			$data = $this->findByPk($this->id === NULL ? -1 : $this->id);
326 332
 
327 333
 			// Check the pulled data id to the current item
328
-			if ($data !== NULL && $data->id == $this->id)
329
-				return $slug;
334
+			if ($data !== NULL && $data->id == $this->id) {
335
+							return $slug;
336
+			}
330 337
 		}
331 338
 
332
-		if ($count == 0 && !in_array($slug, $this->forbiddenRoutes))
333
-			return $slug . $id;
334
-		else
335
-			return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
339
+		if ($count == 0 && !in_array($slug, $this->forbiddenRoutes)) {
340
+					return $slug . $id;
341
+		} else {
342
+					return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
343
+		}
336 344
 	}
337 345
 }
Please login to merge, or discard this patch.
protected/models/CategoriesMetadata.php 3 patches
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -16,83 +16,83 @@
 block discarded – undo
16 16
  */
17 17
 class CategoriesMetadata extends CiiModel
18 18
 {
19
-	/**
20
-	 * Returns the static model of the specified AR class.
21
-	 * @param string $className active record class name.
22
-	 * @return CategoriesMetadata the static model class
23
-	 */
24
-	public static function model($className=__CLASS__)
25
-	{
26
-		return parent::model($className);
27
-	}
19
+    /**
20
+     * Returns the static model of the specified AR class.
21
+     * @param string $className active record class name.
22
+     * @return CategoriesMetadata the static model class
23
+     */
24
+    public static function model($className=__CLASS__)
25
+    {
26
+        return parent::model($className);
27
+    }
28 28
 
29
-	/**
30
-	 * @return string the associated database table name
31
-	 */
32
-	public function tableName()
33
-	{
34
-		return 'categories_metadata';
35
-	}
29
+    /**
30
+     * @return string the associated database table name
31
+     */
32
+    public function tableName()
33
+    {
34
+        return 'categories_metadata';
35
+    }
36 36
 
37
-	/**
38
-	 * @return array validation rules for model attributes.
39
-	 */
40
-	public function rules()
41
-	{
42
-		// NOTE: you should only define rules for those attributes that
43
-		// will receive user inputs.
44
-		return array(
45
-			array('category_id, key, value', 'required'),
46
-			array('category_id', 'numerical', 'integerOnly'=>true),
47
-			array('key, value', 'length', 'max'=>50),
48
-			// The following rule is used by search().
49
-			// Please remove those attributes that should not be searched.
50
-			array('id, category_id, key, value, created, updated', 'safe', 'on'=>'search'),
51
-		);
52
-	}
37
+    /**
38
+     * @return array validation rules for model attributes.
39
+     */
40
+    public function rules()
41
+    {
42
+        // NOTE: you should only define rules for those attributes that
43
+        // will receive user inputs.
44
+        return array(
45
+            array('category_id, key, value', 'required'),
46
+            array('category_id', 'numerical', 'integerOnly'=>true),
47
+            array('key, value', 'length', 'max'=>50),
48
+            // The following rule is used by search().
49
+            // Please remove those attributes that should not be searched.
50
+            array('id, category_id, key, value, created, updated', 'safe', 'on'=>'search'),
51
+        );
52
+    }
53 53
 
54
-	/**
55
-	 * @return array relational rules.
56
-	 */
57
-	public function relations()
58
-	{
59
-		// NOTE: you may need to adjust the relation name and the related
60
-		// class name for the relations automatically generated below.
61
-		return array(
62
-			'category' => array(self::BELONGS_TO, 'Categories', 'category_id'),
63
-		);
64
-	}
54
+    /**
55
+     * @return array relational rules.
56
+     */
57
+    public function relations()
58
+    {
59
+        // NOTE: you may need to adjust the relation name and the related
60
+        // class name for the relations automatically generated below.
61
+        return array(
62
+            'category' => array(self::BELONGS_TO, 'Categories', 'category_id'),
63
+        );
64
+    }
65 65
 
66
-	/**
67
-	 * @return array customized attribute labels (name=>label)
68
-	 */
69
-	public function attributeLabels()
70
-	{
71
-		return array(
72
-			'category_id' => Yii::t('ciims.models.CategoriesMetadata', 'Category ID'),
73
-			'key' 	      => Yii::t('ciims.models.CategoriesMetadata', 'Key'),
74
-			'value'       => Yii::t('ciims.models.CategoriesMetadata', 'Value'),
75
-			'created'	  => Yii::t('ciims.models.CategoriesMetadata', 'Created'),
76
-			'updated' 	  => Yii::t('ciims.models.CategoriesMetadata', 'Updated'),
77
-		);
78
-	}
66
+    /**
67
+     * @return array customized attribute labels (name=>label)
68
+     */
69
+    public function attributeLabels()
70
+    {
71
+        return array(
72
+            'category_id' => Yii::t('ciims.models.CategoriesMetadata', 'Category ID'),
73
+            'key' 	      => Yii::t('ciims.models.CategoriesMetadata', 'Key'),
74
+            'value'       => Yii::t('ciims.models.CategoriesMetadata', 'Value'),
75
+            'created'	  => Yii::t('ciims.models.CategoriesMetadata', 'Created'),
76
+            'updated' 	  => Yii::t('ciims.models.CategoriesMetadata', 'Updated'),
77
+        );
78
+    }
79 79
 
80
-	/**
81
-	 * Retrieves a list of models based on the current search/filter conditions.
82
-	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
83
-	 */
84
-	public function search()
85
-	{
86
-		$criteria=new CDbCriteria;
80
+    /**
81
+     * Retrieves a list of models based on the current search/filter conditions.
82
+     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
83
+     */
84
+    public function search()
85
+    {
86
+        $criteria=new CDbCriteria;
87 87
 
88
-		$criteria->compare('category_id',$this->category_id);
89
-		$criteria->compare('t.key',$this->key,true);
90
-		$criteria->compare('value',$this->value,true);
91
-		$criteria->compare('created',$this->created,true);
92
-		$criteria->compare('updated',$this->updated,true);
88
+        $criteria->compare('category_id',$this->category_id);
89
+        $criteria->compare('t.key',$this->key,true);
90
+        $criteria->compare('value',$this->value,true);
91
+        $criteria->compare('created',$this->created,true);
92
+        $criteria->compare('updated',$this->updated,true);
93 93
 
94
-		return new CActiveDataProvider($this, array(
95
-			'criteria'=>$criteria,
96
-		));
97
-	}
94
+        return new CActiveDataProvider($this, array(
95
+            'criteria'=>$criteria,
96
+        ));
97
+    }
98 98
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -21,15 +21,15 @@  discard block
 block discarded – undo
21 21
 	 * @param string $className active record class name.
22 22
 	 * @return CategoriesMetadata the static model class
23 23
 	 */
24
-	public static function model($className=__CLASS__)
24
+	public static function model ($className = __CLASS__)
25 25
 	{
26
-		return parent::model($className);
26
+		return parent::model ($className);
27 27
 	}
28 28
 
29 29
 	/**
30 30
 	 * @return string the associated database table name
31 31
 	 */
32
-	public function tableName()
32
+	public function tableName ()
33 33
 	{
34 34
 		return 'categories_metadata';
35 35
 	}
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	/**
38 38
 	 * @return array validation rules for model attributes.
39 39
 	 */
40
-	public function rules()
40
+	public function rules ()
41 41
 	{
42 42
 		// NOTE: you should only define rules for those attributes that
43 43
 		// will receive user inputs.
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	/**
55 55
 	 * @return array relational rules.
56 56
 	 */
57
-	public function relations()
57
+	public function relations ()
58 58
 	{
59 59
 		// NOTE: you may need to adjust the relation name and the related
60 60
 		// class name for the relations automatically generated below.
@@ -66,14 +66,14 @@  discard block
 block discarded – undo
66 66
 	/**
67 67
 	 * @return array customized attribute labels (name=>label)
68 68
 	 */
69
-	public function attributeLabels()
69
+	public function attributeLabels ()
70 70
 	{
71 71
 		return array(
72
-			'category_id' => Yii::t('ciims.models.CategoriesMetadata', 'Category ID'),
73
-			'key' 	      => Yii::t('ciims.models.CategoriesMetadata', 'Key'),
74
-			'value'       => Yii::t('ciims.models.CategoriesMetadata', 'Value'),
75
-			'created'	  => Yii::t('ciims.models.CategoriesMetadata', 'Created'),
76
-			'updated' 	  => Yii::t('ciims.models.CategoriesMetadata', 'Updated'),
72
+			'category_id' => Yii::t ('ciims.models.CategoriesMetadata', 'Category ID'),
73
+			'key' 	      => Yii::t ('ciims.models.CategoriesMetadata', 'Key'),
74
+			'value'       => Yii::t ('ciims.models.CategoriesMetadata', 'Value'),
75
+			'created'	  => Yii::t ('ciims.models.CategoriesMetadata', 'Created'),
76
+			'updated' 	  => Yii::t ('ciims.models.CategoriesMetadata', 'Updated'),
77 77
 		);
78 78
 	}
79 79
 
@@ -81,17 +81,17 @@  discard block
 block discarded – undo
81 81
 	 * Retrieves a list of models based on the current search/filter conditions.
82 82
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
83 83
 	 */
84
-	public function search()
84
+	public function search ()
85 85
 	{
86
-		$criteria=new CDbCriteria;
86
+		$criteria = new CDbCriteria;
87 87
 
88
-		$criteria->compare('category_id',$this->category_id);
89
-		$criteria->compare('t.key',$this->key,true);
90
-		$criteria->compare('value',$this->value,true);
91
-		$criteria->compare('created',$this->created,true);
92
-		$criteria->compare('updated',$this->updated,true);
88
+		$criteria->compare ('category_id', $this->category_id);
89
+		$criteria->compare ('t.key', $this->key, true);
90
+		$criteria->compare ('value', $this->value, true);
91
+		$criteria->compare ('created', $this->created, true);
92
+		$criteria->compare ('updated', $this->updated, true);
93 93
 
94
-		return new CActiveDataProvider($this, array(
94
+		return new CActiveDataProvider ($this, array(
95 95
 			'criteria'=>$criteria,
96 96
 		));
97 97
 	}
Please login to merge, or discard this patch.
Braces   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -14,31 +14,31 @@  discard block
 block discarded – undo
14 14
  * The followings are the available model relations:
15 15
  * @property Categories $category
16 16
  */
17
-class CategoriesMetadata extends CiiModel
18
-{
17
+class CategoriesMetadata extends CiiModel
18
+{
19 19
 	/**
20 20
 	 * Returns the static model of the specified AR class.
21 21
 	 * @param string $className active record class name.
22 22
 	 * @return CategoriesMetadata the static model class
23 23
 	 */
24
-	public static function model($className=__CLASS__)
25
-	{
24
+	public static function model($className=__CLASS__)
25
+	{
26 26
 		return parent::model($className);
27 27
 	}
28 28
 
29 29
 	/**
30 30
 	 * @return string the associated database table name
31 31
 	 */
32
-	public function tableName()
33
-	{
32
+	public function tableName()
33
+	{
34 34
 		return 'categories_metadata';
35 35
 	}
36 36
 
37 37
 	/**
38 38
 	 * @return array validation rules for model attributes.
39 39
 	 */
40
-	public function rules()
41
-	{
40
+	public function rules()
41
+	{
42 42
 		// NOTE: you should only define rules for those attributes that
43 43
 		// will receive user inputs.
44 44
 		return array(
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
 	/**
55 55
 	 * @return array relational rules.
56 56
 	 */
57
-	public function relations()
58
-	{
57
+	public function relations()
58
+	{
59 59
 		// NOTE: you may need to adjust the relation name and the related
60 60
 		// class name for the relations automatically generated below.
61 61
 		return array(
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
 	/**
67 67
 	 * @return array customized attribute labels (name=>label)
68 68
 	 */
69
-	public function attributeLabels()
70
-	{
69
+	public function attributeLabels()
70
+	{
71 71
 		return array(
72 72
 			'category_id' => Yii::t('ciims.models.CategoriesMetadata', 'Category ID'),
73 73
 			'key' 	      => Yii::t('ciims.models.CategoriesMetadata', 'Key'),
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
 	 * Retrieves a list of models based on the current search/filter conditions.
82 82
 	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
83 83
 	 */
84
-	public function search()
85
-	{
84
+	public function search()
85
+	{
86 86
 		$criteria=new CDbCriteria;
87 87
 
88 88
 		$criteria->compare('category_id',$this->category_id);
Please login to merge, or discard this patch.