GameConnect / SourceBans

Advanced admin and ban management for the Source game engine
http://www.sourcebans.net
67 stars 30 forks source link

Installed plugin still have "new" status #27

Closed ppalex7 closed 10 years ago

ppalex7 commented 10 years ago

After commit bcdf0c5bf617984bb41cfd0fea992fe50f89ac4b when i'm pressing "install" link, plugin is successfully installed, but his status doesn't changes to "installed" into db;

Something strange happens during $plugin->save();: Before it, $plugin is:

    CommunityBansPlugin#1
    (
        [allowDisable] => true
        [CActiveRecord:_new] => false
        [CActiveRecord:_attributes] => array
        (
            'class' => 'CommunityBans.CommunityBansPlugin'
            'status' => 1
        )
        [CActiveRecord:_related] => array()
        [CActiveRecord:_c] => null
        [CActiveRecord:_pk] => 'CommunityBans.CommunityBansPlugin'
        [CActiveRecord:_alias] => 't'
        [CModel:_errors] => array()
        [CModel:_validators] => null
        [CModel:_scenario] => 'update'
        [CComponent:_e] => null
        [CComponent:_m] => null
    )
    in /home/Alex/www/SourceBans/web/application/controllers/PluginsController.php (70)

but mysql receives this query (from bin log):

    UPDATE `sb_plugins` SET `class`='CommunityBans.CommunityBansPlugin', `status`=0 WHERE `sb_plugins`.`class`='CommunityBans.CommunityBansPlugin'

Did you have any ideas?

ppalex7 commented 10 years ago

The answer is the "unique" rule. Example (at actionInstall):

    $plugin->status = !$plugin->canDisable()
            ?SBPlugin::STATUS_ENABLED
            :SBPlugin::STATUS_INSTALLED;
    Yii::log(CVarDumper::dumpAsString($plugin));
    $plugin->validate();
    Yii::log(CVarDumper::dumpAsString($plugin));

Before Validate plugin model is:

    CommunityBansPlugin#1
    (
        [allowDisable] => true
        [CActiveRecord:_new] => false
        [CActiveRecord:_attributes] => array
        (
            'class' => 'CommunityBans.CommunityBansPlugin'
            'status' => 1
        )
        [CActiveRecord:_related] => array()
        [CActiveRecord:_c] => null
        [CActiveRecord:_pk] => 'CommunityBans.CommunityBansPlugin'
        [CActiveRecord:_alias] => 't'
        [CModel:_errors] => array()
        [CModel:_validators] => null
        [CModel:_scenario] => 'update'
        [CComponent:_e] => null
        [CComponent:_m] => null
    )

And after validate:

    CommunityBansPlugin#1
    (
        [allowDisable] => true
        [CActiveRecord:_new] => false
        [CActiveRecord:_attributes] => array
        (
            'class' => 'CommunityBans.CommunityBansPlugin'
            'status' => '0'
        )
        [CActiveRecord:_related] => array()
        [CActiveRecord:_c] => null
        [CActiveRecord:_pk] => 'CommunityBans.CommunityBansPlugin'
        [CActiveRecord:_alias] => 't'
        [CModel:_errors] => array()
    ...
ErikMinekus commented 10 years ago

Hmm, good catch. That's indeed an issue.

ppalex7 commented 10 years ago

Quick solution - using $plugin->update instead of $plugin->save