0

i try for my Magento 1 Module to create an own Database table. I see my install entry in the core_resource table, but my table is not created.

This is my config.xml:

<config>
<modules>
    <UF_MagentoAdminScriptQueue>
        <version>1.0.0</version>
        <active>true</active>
        <codePool>community</codePool>
        <depends>
            <Mage_Adminhtml />
        </depends>
        <extension_name>MagentoAdminScriptQueue</extension_name>
    </UF_MagentoAdminScriptQueue>
</modules>

<global>
    <models>
        <magentoadminscriptqueue>
            <class>UF_MagentoAdminScriptQueue_Model</class>
            <resourceModel>uf_magentoadminscriptqueue_resource</resourceModel>
        </magentoadminscriptqueue>
        <uf_magentoadminscriptqueue_resource>
            <class>UF_MagentoAdminScriptQueue_Model_Resource</class>
            <entities>
                <queue>
                    <table>uf_adminscriptqueue_queue</table>
                </queue>
            </entities>
        </uf_magentoadminscriptqueue_resource>
    </models>
    <resources>
        <magentoadminscriptqueue_setup>
            <setup>
                <module>UF_MagentoAdminScriptQueue</module>
            </setup>
        </magentoadminscriptqueue_setup>
    </resources>
    <blocks>
        <magentoadminscriptqueue>
            <class>UF_MagentoAdminScriptQueue_Block</class>
        </magentoadminscriptqueue>
    </blocks>
    <helpers>
        <magentoadminscriptqueue>
            <class>UF_MagentoAdminScriptQueue_Helper</class>
        </magentoadminscriptqueue>
    </helpers>
</global>

<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <magentoadminscriptqueue before="Mage_Adminhtml">UF_MagentoAdminScriptQueue_Adminhtml</magentoadminscriptqueue>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

This is my Installationscript sql/mysql4-install-1.0.0.php:

$installer = $this;
$installer->startSetup();

$queueTable = $installer->getTable('uf_adminscriptqueue/queue');

if ($installer->getConnection()->isTableExists($queueTable))
    $installer->getConnection()->dropTable($queueTable);

$table = $installer->getConnection()->newTable($queueTable)
    ->addColumn(
        'entity_id',
        Varien_Db_Ddl_Table::TYPE_INTEGER,
        null,
        array(
            'unsigned' => true,
            'nullable' => false,
            'primary'  => true,
            'identity' => true,
        ),
        'Entity Id'
    )
    ->addColumn(
        'slug',
        Varien_Db_Ddl_Table::TYPE_VARCHAR,
        40,
        array(
            'default' => null,
        ),
        'Slug'
    )
    ->addColumn(
        'name',
        Varien_Db_Ddl_Table::TYPE_VARCHAR,
        40,
        array(
            'default' => null,
        ),
        'Name'
    )
    ->addColumn(
        'status',
        Varien_Db_Ddl_Table::TYPE_SMALLINT,
        null,
        array(
            'unsigned' => true,
            'nullable' => false,
            'default'  => UF_MagentoAdminScriptQueue_Model_Offer::STATUS_NOTRUNNING,
        ),
        'Status'
    )
    ->addColumn(
        'last_run',
        Varien_Db_Ddl_Table::TYPE_DATETIME,
        null,
        array(
            'default'  => null,
        ),
        'Created At'
    )
    ->setComment('UF Script Queue Table');
$installer->getConnection()->createTable($table);

$scripts = array(
    array(
        'slug' => 'getCategories',
        'name' => 'Get Categories'
    ),
    array(
        'slug' => 'importCategories',
        'name' => 'Import Categories'
    ),
    array(
        'slug' => 'exportProductToCsv',
        'name' => 'Export Products to CSV'
    ),
    array(
        'slug' => 'updateMediaGallery',
        'name' => 'Update Media Gallery'
    ),
);

foreach ($scripts as $script) {
    Mage::getModel('uf_adminscriptqueue/queue')
        ->setData($script)
        ->save();
}

$installer->endSetup();

Then i have the UF_MagentoAdminScriptQueue_Model_Script in the Model Directory:

class UF_MagentoAdminScriptQueue_Model_Script extends Mage_Core_Model_Abstract
{
    const STATUS_NOTRUNNING = 1;
    const STATUS_RUNNING    = 2;
    const STATUS_INQUEUE    = 3;

    /**
     * Init
     */
    protected function _construct()
    {
        $this->_init('uf_adminscriptqueue/queue');
    }

    /**
     * Processing object before save data
     *
     * @return Mage_Core_Model_Abstract
     */
    protected function _beforeSave()
    {
        parent::_beforeSave();
    }

    /**
     * Save queue related objects
     *
     * @return $this
     */
    protected function _afterSave()
    {
        return parent::_afterSave();
    }
}

I don't show the code for the resource and collection class, in this files are only the constructor with the init of 'uf_adminscriptqueue/queue'.

Anybody knows what i do wrong?

Cheers Kerstel

Dharman
  • 30,962
  • 25
  • 85
  • 135
Kerstel
  • 1
  • 1

1 Answers1

0

There is mistake in file location: according to your config.xml, setup script should be placed in:

sql/magentoadminscriptqueue_setup/

folder, not in sql. Also, I would suggest to install https://packagist.org/packages/n98/magerun. It helps you to see what actually will be applied when you run setup:upgrade.

$ php vendor/bin/n98-magerun sys:set:in

Before trying to run this command, delete record from core_resource related to installed module version. Don't forget about caches: clear them before run install script again.

mrDinkelman
  • 488
  • 1
  • 9
  • 18