We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

Problem when plugin updates automatically | Forum

Sanusi Yaakub
Sanusi Yaakub Aug 29 '13
Hi,
i need help in creating an automatic plugin update code.

i have created a plugin update, and this update adds some language key/value and also alters the database table..

so, i have followed the coding style of the system plugins and have come to this:
1- i have created
/PLUGINNAME/update/BUILD/update.php
/
PLUGINNAME/update/BUILD/langs.zip
---> langs.zip/language_en/language.xml
---> langs.zip/language_en/PLUGINNAME.xml

2- i have updated the plugin.xml with the current BUILD number

then, when i go to admin manage plugin folder, i got the notification to update the plugin, but when i click the button, these errors appear
-------------------------------------
OW Debug - Warning
Message:     mkdir(): File exists
File:     C:\xampp\htdocs\oxwall-1.5.1\ow_system_plugins\base\bol\language_service.php
Line:     753

OW Debug - Warning
Message:     rmdir(C:\xampp\htdocs\oxwall-1.5.1\ow_pluginfiles/admin\languages\import\PLUGINNAME): Directory not empty
File:     C:\xampp\htdocs\oxwall-1.5.1\ow_utilities\file.php
Line:     181

OW Debug - Warning
Message:     Cant remove directory `C:\xampp\htdocs\oxwall-1.5.1\ow_pluginfiles/admin\languages\import\PLUGINNAME`!
File:     C:\xampp\htdocs\oxwall-1.5.1\ow_utilities\file.php
Line:     183
...

-------------------------------------

and these errors always redirect the users to 500.html page. can anybody help me with this?
The Forum post is edited by Sanusi Yaakub Aug 29 '13
Sanusi Yaakub
Sanusi Yaakub Aug 29 '13
here is a rough solution that i found:
i delete the folder(using file utility) before updating the language, using updater to remove the folder causes the error

UTIL_File::removeDir( BOL_LanguageService::getImportDirPath().'PLUGINNAME' );

is there any smoother workaround for this?
Daisy Team
Daisy Sep 5 '13
The standard update method should work with no problems. So, seems there is plugin logic failure.
Please provide me with the content of these files:
/PLUGINNAME/update/BUILD/update.php
langs.zip/language_en/language.xml

Also, please answer the following questions:

1. Is your site hosted on the local machine?
2. Do you use the standard English package?
3. Why does your plugin create its own directory in \import\ folder?
4. Have you checked the permissions for the ow_pluginfiles folder?
Sanusi Yaakub
Sanusi Yaakub Sep 5 '13
ok, here is the content of the files...

---/PLUGINNAME/update/BUILD/update.php---

<?php
    Updater::getDbo()->query("CREATE TABLE IF NOT EXISTS `".OW_DB_PREFIX."PLUGINNAME_children` (
        `id` int(11) NOT NULL auto_increment,
        `childof` int(11) NOT NULL,
        `name` varchar(255) NOT NULL,
        `url` tinytext NOT NULL,
        PRIMARY KEY(`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;");
    
    UTIL_File::removeDir( BOL_LanguageService::getImportDirPath().'PLUGINNAME' );
    Updater::getLanguageService()->importPrefixFromZip(dirname(__FILE__).DS.'langs.zip', 'PLUGINNAME');
?>

---langs.zip/language_en/language.xml---

<?xml version="1.0" encoding="utf-8"?>
<language tag="en" label="English" rtl="0"/>

and the answers:
1- no, it is hosted by a hosting company, but i do use a local server to develop the plugin
2- yes
3- no, its not. The system did it itself.. maybe because my plugin import the language upon installation. this is some of the content of install.php:

$path = OW::getPluginManager()->getPlugin('PLUGINNAME')->getRootDir() . 'langs.zip';
OW::getLanguage()->importPluginLangs($path, 'PLUGINNAME');

4- no, i use default permission, 0755


Daisy Team
Daisy Sep 5 '13
Please try using the following string to import the language pack in the installation process:

OW::getLanguage()->importPluginLangs(OW::getPluginManager()->getPlugin('PLUGINNAME')->getRootDir() . 'langs.zip', 'PLUGINNAME');

Try using the following code in your update.php file:

$sql = " CREATE TABLE IF NOT EXISTS `". OW_DB_PREFIX. "PLUGINNAME_children` (
 `id` int(11) NOT NULL auto_increment,
 `childof` int(11) NOT NULL,
 `name` varchar(255) NOT NULL,
 `url` tinytext NOT NULL,
 PRIMARY KEY(`id`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;");

    try
    {
        Updater::getDbo()->query($sql);
    }
    catch ( Exception $e )
    {}


$updateDir = dirname(__FILE__) . DS;
Updater::getLanguageService()->importPrefixFromZip($updateDir . 'langs.zip', 'PLUGINNAME');


Also, could you check the plugin functionality on the Linux system, not on Windows.

Finally, the permissions for the ow_pluginfiles directory should be 0777. Try to change them recursively to see if it solve the problem.
The Forum post is edited by Daisy Sep 5 '13