插件安装:postflight未执行,语言文件未重新读取

时间:2013-05-31 11:30:22

标签: php joomla joomla3.0

我正在开发一个插件,并希望在一些文本常量中使用插件ID。所以我想我会做以下事情:在postflight-code中,找到插件的id并将其替换为语言文件。为了轻松“看到”它被执行,我还决定最初使用扩展名“inix”命名语言文件,并将其替换为“ini”作为postflight的一部分。但这不会发生,后续飞行不会执行!为什么呢?

另外,如果您需要花费更多时间进行调查,那么语言文件的处理存在问题,我不知道如何处理:在FIRST安装之后,您会看到文本COM_FOO_PLG_DESC是显示 - 此常量不会替换为其值。如果你那么。去编辑zip并将.ini文件中的版本号更改为2并重新安装,你会注意到这个文本显示了,但仍然是指V1!所以...在安装过程中不会重新读取更新的语言文件 - 我相信应该会发生!所以我也插入了代码来重新加载到postflight中,但是......(见上文)它没有被执行。


整件事可以从http://mbaas.de/plg_foo.zip获取 以下是一些基本要点:

foo.xml:

    <?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" version="1.6" method="upgrade" group="content">
<name>Content - foo</name>
<creationDate>2013-05-30</creationDate>
<version>2.0.0.16</version>
<releaseDate>2013-05-30 12:00:58</releaseDate>
<releaseType>First public release!</releaseType>
<author>Michael Baas</author>
<authorEmail>mb@mbaas.de</authorEmail>
<authorUrl>mbaas.de</authorUrl>
<copyright>(c) 2013 Michael Baas</copyright>
<description>COM_FOO_PLG_DESC</description>
<files>
<filename plugin="foo">foo.php</filename>
<folder>language</folder>
</files>
<scriptfile>foo.scriptfile.php</scriptfile>
<languages folder="language">
<language tag="en-GB">en-GB/en-GB.plg_content_foo.ini</language>
<language tag="de-DE">de-DE/de-DE.plg_content_foo.ini</language>
<language tag="en-GB">en-GB/en-GB.plg_content_foo.sys.inix</language>
<language tag="de-DE">de-DE/de-DE.plg_content_foo.sys.inix</language>
</languages>
</extension>

和foo.scriptfile.php:

    <?php
class plgContentcbmdebugInstallerScript
{
    public function __constructor(JAdapterInstance $adapter)
    {
    }
    static function loadLanguage() {
        $lang =& JFactory::getLanguage();
        $lang->load('plgContentfoo', JPATH_ADMINISTRATOR , null , true);
    }

    function preflight($type, $adapter)
    {
        echo "<b>prelight!</b>";
        $table        = JTable::getInstance('extension');
        if ($table->load(array('element' => 'foo', 'type' => 'plugin')))
        {
            $id=$table->extension_id;
            $arr = array(
            0=>"de-DE",
            1=>"en-GB"
            );
            foreach($arr as $iso) {
                $fl_lng = JPATH_ADMINISTRATOR  . "/language/$iso/$iso.plg_content_foo.sys.ini";
                unlink($fl_lng);
            }
        }
    }

    function postflight($type, $adapter)
    {
        echo "<b>postflight!</b>";
        $table        = JTable::getInstance('extension');
        if ($table->load(array('element' => 'foo', 'type' => 'plugin')))
        {
            $id=$table->extension_id;
            $arr = array(
            0=>"de-DE",
            1=>"en-GB"
            );
            foreach($arr as $iso) {
                $fl_lngx = JPATH_PLUGINS  . "/content/cbmdebug/language/$iso/$iso.plg_content_foo.sys.inix";
                $fl_lng = JPATH_ADMINISTRATOR  . "/language/$iso/$iso.plg_content_cbmdebug.sys.ini";
                $xx = file_get_contents($fl_lngx);
                $xx = str_replace("tHiS-Id",$id,$xx);
                file_put_contents($fl_lng,$xx);
                unlink($fl_lngx);
            }
            self::loadLanguage();
        }
    }
}
?>

1 个答案:

答案 0 :(得分:3)

首先,脚本文件的类名需要与插件的名称相关。这意味着如果插件是名为foo的内容插件,则类名必须为plgContentFooInstallerScript。 但是,脚本文件的类名是plgContentcbmdebugInstallerScript。我认为你重命名插件显示在这里,但错过了那个。假设您的插件名为cbmdebug,则类名仍然是错误的,因为它应该是plgContentCbmdebugInstallerScript(注意大写字符)。

至于加载的语言文件。在安装期间,仅加载sys.ini文件。由于您的包中没有这样的文件,Joomla无法加载任何内容。

旁注:为什么你甚至试图操纵语言字符串?您是否尝试使用JText::sprintf()http://api.joomla.org/Joomla-Platform/Language/JText.html#sprintf)。它允许您将插件ID传递给PHP sprintf函数插入的语言字符串。