Magento 1.9 安装脚本不是 运行

Magento 1.9 install script not running

我是 Magento 的初学者,我是从开发小扩展开始的。

我已经安装好了,一切正常。但出于某种原因,我决定重新安装它。我从 core_resource table 中删除了行,我也从数据库中删除了模块 tables。在 .xml 配置文件中,我输入了 false

现在扩展无法正常工作(当然)。但它仍然出现在配置 -> 高级 -> 模块输出中!我不知道为什么。我什至刚刚从目录中删除了所有文件和文件夹,我清除了 Magento 缓存(实际上在我的系统中设置为 "disabled")

这里是config.xml:

<?xml version="0.0.1" encoding="UTF-8" ?>
<config>
    <modules>
        <Anglingdirect_Jobadverts>
            <version>0.0.1</version>
        </Anglingdirect_Jobadverts>
    </modules>
    <global>
        <helpers>
            <jobadverts>
                <class>Anglingdirect_Jobadverts_Helper</class>
            </jobadverts>
        </helpers>
        <blocks>
            <jobadverts>
                <class>Anglingdirect_Jobadverts_Block</class>
            </jobadverts>
        </blocks>
        <models>
            <jobadverts>
                <class>Anglingdirect_Jobadverts_Model</class>
                <resourceModel>jobadverts_mysql4</resourceModel>
            </jobadverts>
            <jobadverts_mysql4>
                <class>Anglingdirect_Jobadverts_Model_Mysql4</class>
                <entities>
                    <advert>
                        <table>job_adverts</table>
                    </advert>
                    <category>
                        <table>job_categories</table>job
                    </category>
                    <application>
                        <table>job_applications</table>
                    </application>
                    <location>
                        <table>aw_storelocator_location</table>
                    </location>
                </entities>
            </jobadverts_mysql4>
        </models>
        <resources>
            <jobadverts_setup>
                <setup>
                    <module>Anglingdirect_Jobadverts</module>
                    <class>Anglingdirect_Jobadverts_Model_Mysql4_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </jobadverts_setup>
            <jobadverts_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </jobadverts_read>
            <jobadverts_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </jobadverts_write>
        </resources>

    </global>
    <frontend>
        <routers>
            <jobadverts>
                <use>standard</use>
                <args>
                    <module>Anglingdirect_Jobadverts</module>
                    <frontName>career</frontName>
                </args>
            </jobadverts>
        </routers>
        <layout>
            <updates>
                <jobadverts>
                    <file>jobadverts.xml</file>
                </jobadverts>

            </updates>
        </layout>
    </frontend>
    <admin>
        <routers>
            <jobadverts>
                <use>admin</use>
                <args>
                    <module>Anglingdirect_Jobadverts</module>
                    <frontName>adminhtml_jobadverts</frontName>
                </args>
            </jobadverts>
        </routers>
    </admin>
    <!--<admin>-->
        <!--<routers>-->
            <!--<Anglingdirect_Jobadverts>-->
                <!--<use>admin</use>-->
                <!--<args>-->
                    <!--<module>Anglingdirect_Jobadverts</module>-->
                    <!--<frontName>admin_jobadverts</frontName>-->
                <!--</args>-->
            <!--</Anglingdirect_Jobadverts>-->
        <!--</routers>-->
    <!--</admin>-->
    <adminhtml>
        <menu>
            <adextensions module="anglingdirect_jobadverts">
                <title>AD Extensions</title>
                <sort_order>100</sort_order>
                <children>
                    <jobadverts module="jobadverts">
                        <title>Job adverts</title>
                        <sort_order>150</sort_order>
                        <children>
                            <application module="jobadverts">
                                <title>Post a job</title>
                                <sort_order>0</sort_order>
                                <action>adminhtml_jobadverts/adminhtml_advert/new</action>
                            </application>

                            <advert module="jobadverts">
                                <title>Job management</title>
                                <sort_order>10</sort_order>
                                <action>adminhtml_jobadverts/adminhtml_advert/index</action>
                            </advert>

                            <browse module="jobadverts">
                                <title>Job applications</title>
                                <sort_order>20</sort_order>
                                <action>adminhtml_jobadverts/adminhtml_application</action>
                            </browse>
                        </children>
                    </jobadverts>
                </children>
            </adextensions>
        </menu>

        <layout>
            <updates>
                <jobadverts module="jobadverts">
                    <file>jobadverts.xml</file>
                </jobadverts>
            </updates>
        </layout>
    </adminhtml>

</config> 

这是我的安装 mysql4-install-0.1.0.php 脚本:

<?php
/* @var $installer Mage_Catalog_Model_Resource_Setup */
$installer->startSetup();
// anglingdirect_jobadverts/job_adverts
$table_adv = $installer->getConnection()
    ->newTable($installer->getTable('job_adverts'))
    ->addColumn('job_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        'identity' => true,
        'unsigned' => true,
        'nullable' => false,
        'primary' => true,
    ),'job post id')
    ->addColumn('job_cat_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        'nullable' => false,
    ),'Job category ID')
    ->addColumn('job_title', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
        'nullable' => false,
    ),'Job Title')
    ->addColumn('job_hours', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
        'nullable' => false,
    ),'Working time')
    ->addColumn('job_salary', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
        'nullable' => false,
    ),'Salary')
    ->addColumn('job_location', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        'nullable' => false,
    ),'Location')
    ->addColumn('job_active', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        'nullable' => false,
    ), 'Advert status: removed, active')
    ->addColumn('job_descr', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
        'nullable' => false,
    ), 'Full job description')
    ->setComment('Job adverts table');

$table_app = $installer->getConnection()->newTable($installer->getTable('job_applications'))
    ->addColumn('job_app_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        'identity' => true,
        'unsigned' => true,
        'nullable' => false,
        'primary' => true,
    ),'job post id')
    ->addColumn('job_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        'nullable' => false,
    ),'Application ID')
    ->addColumn('applicant_name', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
        'nullable' => false,
    ),'Applicant full name')
    ->addColumn('applicant_email', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
        'nullable' => false,
    ),'Contact email')
    ->addColumn('applicant_letter', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
        'nullable' => false,
    ),'Motivation letter')
    ->addColumn('applicant_cv', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
        'nullable' => false,
    ),'path to file with cv')
    ->addColumn('applicant_status', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        'nullable' => false,
    ), 'Applicant succeed, application declined, removed')
    ->setComment('Job applications table');


$table_cat = $installer->getConnection()->newTable($installer->getTable('job_categories'))
    ->addColumn('job_cat_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        'identity' => true,
        'unsigned' => true,
        'nullable' => false,
        'primary' => true,
    ),'Category ID')
    ->addColumn('job_cat_path', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
        'nullable' => false,
    ),'Category title')
    ->addColumn('job_cat_title', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
        'nullable' => false,
    ),'Category title')
    ->addColumn('job_cat_image', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
        'nullable' => false,
    ),'Category image')

    ->addIndex($installer->getIdxName('job_categories', array('job_cat_id')),array('job_cat_id'))
    ->setComment('Job categories table');

$installer->getConnection()->createTable($table_adv);
$installer->getConnection()->createTable($table_app);
$installer->getConnection()->createTable($table_cat);

$installer->endSetup();

文件夹结构如下: Screenshot of my extension folder structure

在这种情况下如何重新安装我的扩展程序?请帮助

逐步完成 this article 以确保您对设置资源的作用、它们的工作方式以及如何解决它们没有任何误解。

完成后,根据您在此问题线程中所说的一切,听起来您正在获取资源 "installed",但您的安装脚本永远不会 运行。我的猜测是您在

中使用的版本号
//0.0.1 is your version number
mysql4-install-0.0.1.php

与您的模块版本不匹配

<modules>
    <Nie_Nie>
        <version>?.?.?</version>
    </Nie_Nie>
</modules>

那些应该匹配 运行 的脚本。我 认为 Magento 足够聪明 运行 如果它找到以前的版本,但是设置资源中的代码是那种很难遵循的代码,所以我总是确保它们匹配。

无论如何,当 magento 运行 是您的设置资源时,您可以通过以下方式查看它试图 运行 的文件。从 core_resource 中删除与您的模块相关的任何条目。清除缓存。然后在setup中找到以下位置class

File: app/code/core/Mage/Core/Model/Resource/Setup.php

protected function _modifyResourceDb($actionType, $fromVersion, $toVersion)
{
    ... 

    $sqlFilesDir = Mage::getModuleDir('sql', $modName).DS.$this->_resourceName;        

    if (!is_dir($sqlFilesDir) || !is_readable($sqlFilesDir)) {
        return false;
    }

    ...

    $sqlDir->close();

    if (empty($arrAvailableFiles)) {
        return false;
    }

    ...

    $arrModifyFiles = $this->_getModifySqlFiles($actionType, $fromVersion, $toVersion, $arrAvailableFiles);
    if (empty($arrModifyFiles)) {
        return false;
    }

然后修改它们以添加一些临时调试异常

    if (!is_dir($sqlFilesDir) || !is_readable($sqlFilesDir)) {
        throw new Exception("$sqlFilesDir not found");
        return false;
    }

    ...

    if (empty($arrAvailableFiles)) {
        throw new Exception("No files found to run");
        return false;
    }

    ...

    $arrModifyFiles = $this->_getModifySqlFiles($actionType, $fromVersion, $toVersion, $arrAvailableFiles);
    if (empty($arrModifyFiles)) {
        throw new Exception("No valid upgrade files found to run for ");
        return false;
    }

    throw new Exception("If you're getting here, we have a file.  Remove your exceptions here and place one in your installer to make sure it's the one you think it is.");

重新加载页面,您将收到异常文本,抱怨 Magento 无法找到任何内容。这应该足以帮助您追踪 Magento 试图 运行 但未能找到的安装程序脚本。请记住删除 core_resource 中模块的行并清除缓存。 (Magento 缓存哪些模块需要检查 install/upgrade)

如果这不起作用,请开始深入研究 applyAllDataUpdates 的逻辑并找出为什么 class 不包含您的安装程序文件。

已解决。问题是因为我没有 class:

的文件

Anglingdirect_Jobadverts_Model_Mysql4_Setup

现在好了。我从项目文件夹中删除了这个扩展文件并将它们返回。然后安装脚本有 运行.

干杯