Magento 1.9安装脚本未运行

时间:2017-07-17 09:43:37

标签: php magento install

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

我已经安装好了,一切都很好。但由于某种原因,我决定重新安装它。我从core_resource表中删除了行,我也从DB中删除了模块表。在.xml配置文件中我放错了

现在扩展功能无效(当然)。但它仍然显示在配置 - >高级 - >模块输出!我不明白为什么。我甚至刚从目录中删除了所有文件和文件夹,我清除了Magento缓存(实际上在我的系统中设置为“禁用”)

这是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

如何在这种情况下重新安装我的分机?请帮忙

2 个答案:

答案 0 :(得分:0)

完成this article工作,确保您对设置资源的功能,工作方式以及如何对其进行故障排除有任何误解。

一旦你完成了这一切,从你在这个问题线程中所说的一切,听起来你正在“安装”你的资源,但你的安装脚本永远不会运行。我的猜测是你在

中使用的版本号
//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中的所有条目。清除缓存。然后在安装程序类

中找到以下位置
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缓存哪些模块需要检查安装/升级)

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

答案 1 :(得分:0)

解决。问题是因为我没有文件类:

  

Anglingdirect_Jobadverts_Model_Mysql4_Setup

现在没事了。我从项目文件夹中删除了此扩展文件并将其返回。然后安装脚本已经运行。

干杯