5

I've created an installer script which does its job, but the data-install script doesn't seem to be running and I'm not sure why. Here is my data-install script:

<?php
    $defaultCategories = array(
        array(
            'category_name' => 'Header 1',
            'enabled' => true
        ),
        array(
            'category_name' => 'Header 2',
            'enabled' => true
        ),
        array(
            'category_name' => 'Header 3',
            'enabled' => true
        )
    );

    $data = Mage::getModel('namespace_module/table_name');
    $data->setData($defaultCategories)->save();

I don't see what's wrong? (If anyone needs more file contents posted let me know)

UPDATE 1

I've added logging to my file to see if the log gets created, but it doesn't.

Mage::log($defaultCategories, null, 'mylogfile.log');
Mage::log('------ BREAK ------', null, 'mylogfile.log');
Mage::log($data, null, 'mylogfile.log');

is what I used to (try to) create the log file but no success.

File Tree:

|----Namespace
|--------Module
|------------Block
|----------------Adminhtml
|--------------------Catalog
|------------------------Product
|----------------------------Tab.php
|------------controllers
|----------------Adminhtml
|--------------------IndexController.php
|------------etc
|----------------adminhtml.xml
|----------------config.xml
|------------Helper
|----------------Data.php
|------------Model
|----------------Resource
|--------------------TableOne
|------------------------Collection.php
|--------------------TableTwo
|------------------------Collection.php
|--------------------TableOne.php
|--------------------TableTwo.php
|------------sql
|----------------namespace_module_setup
|--------------------data-install-0.9.6.php
|--------------------mysql4-install-0.9.6

and finally config.xml:

0.9.6

<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <namespace_module before="Mage_Adminhtml">Namespace_Module_Adminhtml</namespace_module>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

<adminhtml>
    <layout>
        <updates>
            <namespace_module>
                <file>module.xml</file>
            </namespace_module>
        </updates>
    </layout>

    <events>
        <catalog_product_save_after>
            <observers>
                <namespace_module_save_after>
                    <type>singleton</type>
                    <class>namespace_module/observer</class>
                    <method>saveVideoTabData</method>
                </namespace_module_save_after>
            </observers>
        </catalog_product_save_after>
    </events>
</adminhtml>

<global>
    <helpers>
        <namespace_module>
            <class>Namespace_Module_Helper</class>
        </namespace_module>
    </helpers>

    <blocks>
        <namespace_module>
            <class>Namespace_Module_Block</class>
        </namespace_module>
    </blocks>

    <models>
        <namespace_module>
            <class>Namespace_Module_Model</class>
            <resourceModel>namespace_module_resource</resourceModel>
        </namespace_module>

        <namespace_module_resource>
            <class>Namespace_Module_Model_Resource</class>
            <entities>
                <tableone>
                    <table>namespace_module_tableone</table>
                </tabletwo>

                <tabletwo>
                    <table>namespace_module_tabletwo</table>
                </tabletwo>
            </entities>
        </namespace_module_resource>
    </models>

    <resources>
        <namespace_module_setup>
            <setup>
                <module>Namespace_Module</module>
            </setup>
        </namespace_module_setup>

        <namespace_module_write>
            <connection>
                <use>core_write</use>
            </connection>
        </namespace_module_write>

        <namespace_module_read>
            <connection>
                <use>core_read</use>
            </connection>
        </namespace_module_read>
    </resources>
</global>

UPDATE 2

I tested to see if my script was being read by adding a php error, but no errors came up and it updated the data version in database. There must be something I'm missing? Any other files you think would be relavant please comment.

Thanks

1

You must move your data-install-0.9.6.php to data/namespace_module_setup folder:

File Tree:

|----Namespace
|--------Module
|------------Block
|----------------Adminhtml
|--------------------Catalog
|------------------------Product
|----------------------------Tab.php
|------------controllers
|----------------Adminhtml
|--------------------IndexController.php
|------------data    
|----------------namespace_module_setup
|--------------------data-install-0.9.6.php
|------------etc
|----------------adminhtml.xml
|----------------config.xml
|------------Helper
|----------------Data.php
|------------Model
|----------------Resource
|--------------------TableOne
|------------------------Collection.php
|--------------------TableTwo
|------------------------Collection.php
|--------------------TableOne.php
|--------------------TableTwo.php
|------------sql
|----------------namespace_module_setup
|--------------------mysql4-install-0.9.6.php

More information here

0

Magento will run the installer script, creating the new table, then it will run the data script filling it with some initial values. Magento keeps track of which scripts it ran in the core_resource table. There are two columns, one called “version” which is the version of the installers it has gone through, and also “data_version” which keeps track, separately, what version of data scripts it has run. This means that if a data script fails, Magento wont try to rerun your installer for that version.

Do check your module and data version.

  • Hi. Not 100% correct. If any install or data setup fails, magento core will trap that and not increse/set the version in the resource table. – ProxiBlue Nov 1 '16 at 4:19
  • I've already checked them and checked to see version, then update my version, check core_resource and it updates, but my data just isn't going through – 123TFO Nov 2 '16 at 19:08

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.