Test Failed
Push — master ( c2af76...a0e4e3 )
by Mihail
05:19
created

update_cms_310::up()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 41
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 6
eloc 21
nc 32
nop 0
dl 0
loc 41
rs 8.9617
c 2
b 0
f 0
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
0 ignored issues
show
Coding Style Compatibility introduced by zenn
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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);
0 ignored issues
show
Bug introduced by zenn
'approve_token' of type string is incompatible with the type array expected by parameter $attributes of Illuminate\Database\Eloquent\Model::update(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
            ->update(/** @scrutinizer ignore-type */ 'approve_token', null);
Loading history...
Bug introduced by zenn
null of type null is incompatible with the type array expected by parameter $options of Illuminate\Database\Eloquent\Model::update(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
            ->update('approve_token', /** @scrutinizer ignore-type */ null);
Loading history...
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
}