3

When uninstalling my plugin, only one table is removed. Two others are left behind. Any suggestions what I'm doing wrong? Could it be naming with and without the underscore?

The good:

<?php
namespace Craft;

class Calendar37Record extends BaseRecord
{
    public function getTableName() {
        return 'calendar37';
    }
    protected function defineAttributes() { 
        return array(
            'event_id'   => AttributeType::Number,
            'dateYmd'    => AttributeType::String,
            'timestr'    => AttributeType::String,
            'alt_text'   => AttributeType::String,
            'css_class'  => AttributeType::String,
            'userJson'   => AttributeType::String,
        );
    }
    public function defineIndexes() {
        return array(
            array('columns' => array('event_id', 'dateYmd'), 'key' => true),
        );
    }
}

and the bad:

<?php
namespace Craft;

class Calendar37_SubsetsRecord extends BaseRecord
{
    public function getTableName() {
        return 'calendar37_Subsets';
    }
    protected function defineAttributes() { 
        return array(
            'handle'              => AttributeType::String,
            'title'               => AttributeType::String,
            'categoriesToInclude' => AttributeType::String,
            'categoriesToExclude' => AttributeType::String,
            );
    }
    public function defineIndexes() {
        return array(
            array('columns' => array('handle'), 'unique' => true),
        );
    }
}

Bad #2:

<?php
namespace Craft;

class Calendar37_ViewsRecord extends BaseRecord
{
    public function getTableName() {
        return 'calendar37_Views';
    }
    protected function defineAttributes() { 
        return array(
            'subsetId'     => AttributeType::String,
            'startDateYmd' => AttributeType::String,
            'endDateYmd'   => AttributeType::String,
            'htmlBefore'   => array(AttributeType::String, 'column' => ColumnType::Text, 'required' => false),
            'htmlAfter'    => array(AttributeType::String, 'column' => ColumnType::Text, 'required' => false),
        );
    }
    public function defineIndexes() {
        return array(
            array('columns' => array('subsetId', 'startDateYmd' ), 'key' => true),
        );
    }
}
2

Thanks for that tip, Lindsey, but here's what happened: I changed calendar37 to calendar37_Occurrences and then all three tables wouldn't uninstall. It turns out that the issue is having a capital letter after the underscore. So it seems like an "undocumented feature" that you can make plugin tables persist after uninstall by including a capital letter after the underscore.

return 'calendar37_Subsets';
return 'calendar37_Views';

needed to become:

return 'calendar37_subsets';
return 'calendar37_views';
| improve this answer | |
  • 1
    Glad you figured it out! I'd actually call that a bug more than a feature... If Craft decides to install a table, it should be equally willing to uninstall it. – Lindsey D Dec 8 '15 at 19:02
1

This is a little bit speculative, so let me know if it turns out to be incorrect...

When you use a non-underscored Record name, you're telling Craft that this is the one-and-only, definitive Record. When you use an underscored Record name, you're telling Craft that this Record is one-of-many. I have a vague recollection of similar behavior with Variables or Controllers too.

Hard to say if that would be considered a "bug" or a "feature". Pixel & Tonic may have a sound reason why that restriction exists.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.