Magento – Data install script wasn’t run

data-installmagento-1.9module

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

Best Answer

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

Related Topic