|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Ffcms\Core\Migrations\MigrationInterface; |
|
4
|
|
|
use Ffcms\Core\Migrations\Migration; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Class update_cms_310 |
|
8
|
|
|
*/ |
|
9
|
|
|
class update_cms_310 extends Migration implements MigrationInterface |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
const UPDATE_EXTENSIONS = ['User', 'Profile', 'Content', 'Feedback', 'Search', 'Sitemap', 'Comments', 'Newcontent', 'Contenttag', 'Newcomment']; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Implement new update changes |
|
15
|
|
|
* @return void |
|
16
|
|
|
*/ |
|
17
|
|
|
public function up() |
|
18
|
|
|
{ |
|
19
|
|
|
// set nullable varchar type for token column |
|
20
|
|
|
$this->getSchema()->table('users', function($table){ |
|
21
|
|
|
$table->string('approve_token', 128)->nullable()->default(null)->change(); |
|
22
|
|
|
}); |
|
23
|
|
|
// set approve_token = null where it like '0' str or '' |
|
24
|
|
|
\Apps\ActiveRecord\User::where('approve_token', '=', '0') |
|
25
|
|
|
->update('approve_token', null); |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
// update comment posts architecture: add app_name and app_id relationship |
|
28
|
|
|
if (!$this->getSchema()->hasColumn('comment_posts', 'app_name')) { |
|
29
|
|
|
$this->getSchema()->table('comment_posts', function($table) { |
|
30
|
|
|
$table->string('app_name')->after('id'); |
|
31
|
|
|
}); |
|
32
|
|
|
} |
|
33
|
|
|
if (!$this->getSchema()->hasColumn('comment_answers', 'app_relation_id')) { |
|
34
|
|
|
$this->getSchema()->table('comment_answers', function($table){ |
|
35
|
|
|
$table->integer('app_relation_id')->unsigned()->default(0)->after('app_name'); |
|
36
|
|
|
}); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
\Apps\ActiveRecord\App::whereIn('sys_name', static::UPDATE_EXTENSIONS) |
|
40
|
|
|
->update(['version' => '1.0.1']); |
|
41
|
|
|
|
|
42
|
|
|
// @todo: add algo to find app_name & app_id for oldest comments |
|
43
|
|
|
if ($this->getSchema()->hasColumn('comment_posts', 'pathway')) { |
|
44
|
|
|
$this->getSchema()->table('comment_posts', function($table){ |
|
45
|
|
|
$table->dropColumn('pathway'); |
|
46
|
|
|
}); |
|
47
|
|
|
} |
|
48
|
|
|
// remove comment_hash column from content |
|
49
|
|
|
if ($this->getSchema()->hasColumn('contents', 'comment_hash')) { |
|
50
|
|
|
$this->getSchema()->table('contents', function($table) { |
|
51
|
|
|
$table->dropColumn('comment_hash'); |
|
52
|
|
|
}); |
|
53
|
|
|
} |
|
54
|
|
|
// remove user login column |
|
55
|
|
|
if ($this->getSchema()->hasColumn('users', 'login')) { |
|
56
|
|
|
$this->getSchema()->table('users', function($table) { |
|
57
|
|
|
$table->dropColumn('login'); |
|
58
|
|
|
}); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return void |
|
64
|
|
|
*/ |
|
65
|
|
|
public function down() |
|
66
|
|
|
{ |
|
67
|
|
|
parent::down(); // TODO: Change the autogenerated stub |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Seed created table via up() method with some data |
|
72
|
|
|
* @return void |
|
73
|
|
|
*/ |
|
74
|
|
|
public function seed() |
|
75
|
|
|
{ |
|
76
|
|
|
// TODO: Implement seed() method. |
|
77
|
|
|
} |
|
78
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.