Page 1 of 2
[OpenCart Package Installer] - Design Phase
Posted: Wed Nov 04, 2009 11:53 pm
by Qphoria
So I have been working on and off with an idea that a few other scripts like SMF and Wordpress offer... A package installer. These allow you upload a zip file (or link to one online) and click "install" which will then
- Extract the zip file
- Test that it will work on your version
- Create the needed directories & files
- Modify existing code (backing up the originals)
- Keeps a record of which mods are installed
This makes mods that affect core files much easier to install and easier to maintain.
SMF uses an XML based script like the one below:
Code: Select all
<operation>
<search position="after">string1</search>
<add>string2</add>
<search>xxx</search>
<replace>yyy</replace>
</operation>
Which isn't a bad system as it uses very expandable but structured xml design and could be adapted easily into OpenCart. The caveat is that its mostly manual, modders would have to create this xml file along with their mods.
Wordpress has a fairly advanced plugin API that seems quite involved, so I'm not really looking to their system.
PHPBB has a community created "EasyMod" addon that does something similar to the way that I usually type in the forums when explaining mods
Code: Select all
--- FIND ---
string 1
-------------
--- BEFORE, ADD ---
string 2
-------------
Which tho seems a bit loose, works pretty well after many years of improvement.
.patch
The last option I am looking into are ".patch" files. Patch files are popular on linux as they are generated from using the "diff" program. What's great about patch files is how easy they are to create and use, and that a single file can be used to create full directories, files, mods, etc.
The way it works is, You have 2 folders. Lets say v132_orig and v132_mods
v132_orig is the original code from the zip file
v132_mods has all your mods you've made for v132
You simply run "diff -ur v132_orig v132_mods > mychanges.patch"
That will generate a file of all the differences between the 2 folders and output it in a unified format to a single file.
This can be done easily in Windows as well by downloading the GnuWin32 diff package which includes the diff program.
I have a php patching script that can take the resulting patch file and execute it on your store, making all the changes needed. I can do this from the admin area by simply uploading the patch file and clicking "install". That's it!
So I'm leaning towards patch files at this time, at least for the first step. Perhaps later additional methods could be added. But I'd like to hear what others might have to say about it. Or other package installing systems you've used and liked.
Re: [OpenCart Package Installer] - Design Phase
Posted: Thu Nov 05, 2009 12:36 am
by Xsecrets
sounds like a great idea, the only question would be how will it handle conflicts as you know they are bound to arise.
Re: [OpenCart Package Installer] - Design Phase
Posted: Thu Nov 05, 2009 12:38 am
by Qphoria
It will check the file first to ensure that the lines it is looking for are found. otherwise it will not install
Re: [OpenCart Package Installer] - Design Phase
Posted: Thu Nov 05, 2009 2:30 am
by twiggy
This could be grate for updating versions?
Re: [OpenCart Package Installer] - Design Phase
Posted: Thu Nov 05, 2009 3:34 am
by Qphoria
yes.. a quick patch could be created between v1.3.x and v1.3.y and done
Re: [OpenCart Package Installer] - Design Phase
Posted: Thu Nov 05, 2009 5:08 am
by JNeuhoff
How would it handle the following case:
contribution-1 patches several Opencart core files, such as the menu.php
contribution-2 patches the same Opencart core files
Re: [OpenCart Package Installer] - Design Phase
Posted: Thu Nov 05, 2009 6:10 am
by Qphoria
Well a patch file searches the changed lines
Example:
Patching 1.3.2 to 1.3.3
Code: Select all
diff -urP opencart_v1.3.2\upload\admin\controller\common\home.php opencart_v1.3.3\upload\admin\controller\common\home.php
--- opencart_v1.3.2\upload\admin\controller\common\home.php Thu Aug 13 21:15:04 2009
+++ opencart_v1.3.3\upload\admin\controller\common\home.php Wed Nov 04 01:46:42 2009
@@ -103,11 +103,14 @@
$this->model_localisation_currency->updateCurrencies();
}
- $this->id = 'content';
$this->template = 'common/home.tpl';
- $this->layout = 'common/layout';
+ $this->children = array(
+ 'common/header',
+ 'common/footer',
+ 'common/menu'
+ );
- $this->render();
+ $this->response->setOutput($this->render(TRUE));
}
the --- sign refers to the old file
the +++ sign refers to the new file
- removes a line
+ adds a line
@@ -103,11 +103,14 @@ refers to the line numbers and number of changed lines
So its a per-line change
The only way there would be a clash is if 2 mods are making the same change, which wouldn't make sense anyway. In that case, the autoinstaller would skip the file and you'd have to manually edit it.
Re: [OpenCart Package Installer] - Design Phase
Posted: Thu Nov 05, 2009 8:42 am
by Leon
This is a very nice idea Qphoria.
What would be really great would be if someone could code an addon or something for a program, that actually tracks what you do, and automatically writes instructions to perform the changes as you make them. This would speed up the process tenfold, because you would simply be modifying files as you normally would, and the program writes all of the changes that you make as you make them.
A little ambitious perhaps, and for sure i definitely can't write this :p
Re: [OpenCart Package Installer] - Design Phase
Posted: Tue Dec 22, 2009 6:21 pm
by Yakiv
If there was a package installer, that would handle the upgrades as a diff patch and if we could download these patches and "hack the patch" to suit our set-up, this would certainly streamline a lot. Interesting thread.
Re: [OpenCart Package Installer] - Design Phase
Posted: Tue Dec 22, 2009 9:21 pm
by fido-x
What about permissions on files? For files to be patched, they would have to be writable. Brings up a few security issues, I would think.
Re: [OpenCart Package Installer] - Design Phase
Posted: Tue Dec 22, 2009 11:07 pm
by Qphoria
By default, all files are typically writable by the "owner" anyway. Only config.php and admin/config.php are normally unwritable
Re: [OpenCart Package Installer] - Design Phase
Posted: Tue Dec 22, 2009 11:34 pm
by fido-x
Qphoria wrote:By default, all files are typically writable by the "owner" anyway. Only config.php and admin/config.php are normally unwritable
True. But it's not the "owner" of the files that will making the changes, it the server user, typically "apache".
Re: [OpenCart Package Installer] - Design Phase
Posted: Tue Dec 22, 2009 11:46 pm
by Xsecrets
fido-x wrote:Qphoria wrote:By default, all files are typically writable by the "owner" anyway. Only config.php and admin/config.php are normally unwritable
True. But it's not the "owner" of the files that will making the changes, it the server user, typically "apache".
actually if you are using suphp which most hosts are these days (at least ones that are security conscious) then it will be the owner that is editing the files when you run a php script.
Re: [OpenCart Package Installer] - Design Phase
Posted: Wed Dec 23, 2009 9:31 am
by Yakiv
In your original post, you had said, "I have a php patching script that can take the resulting patch file and execute it on your store, making all the changes needed. I can do this from the admin area by simply uploading the patch file and clicking "install". That's it!"
Do you have this available for us to test? And is it something that could be "run" through SSH?
Re: [OpenCart Package Installer] - Design Phase
Posted: Wed Dec 23, 2009 10:31 am
by Qphoria
fido-x wrote:Qphoria wrote:By default, all files are typically writable by the "owner" anyway. Only config.php and admin/config.php are normally unwritable
True. But it's not the "owner" of the files that will making the changes, it the server user, typically "apache".
Even if "owner" is set, then step 1 can easily be
1. "Set all files to 755"
2. Run the patch
3. "Restore all files to 644"
But most files are always set to 755/777 from the start anyway, so only the random weirdo will have to actually change his files. It's the least of the worries at this point. Bigger security risks include people from accidentally changing something and how to handle backups.
SMF creates a tilde (~) version of the most recent change, but it only archives it one patch back.
Yakiv wrote:In your original post, you had said, "I have a php patching script that can take the resulting patch file and execute it on your store, making all the changes needed. I can do this from the admin area by simply uploading the patch file and clicking "install". That's it!"
Do you have this available for us to test? And is it something that could be "run" through SSH?
It is run through php. Its a php script that mimics the unix "patch" program. It is not ready for primetime or testing yet.
Re: [OpenCart Package Installer] - Design Phase
Posted: Wed Feb 03, 2010 12:38 am
by Qphoria
Ok.. So I want to get the ball rolling on this.
I am thinking it can be done in phases. My ideas are:
Phase I: Zip File Uploader/Installer (file copy only)
Since most modders seem to grasp the folder structure design when making mods, we can make it one step simpler for store owners by allowing them to browse to the "zip" file and click "install". Planned features of the installer will be:
1. upload the zip file.
2. extract it into the correct folders
3. backup any files that will be overwritten
4. Support wildcards or php variable names
There would be support for variables in the names to trigger the special functionality, like when uploading template files. They are typically uploaded to "default". But instead it could be smart enough to copy to the current theme.
Phase II: Automatic File Edits
As there are many mods that require changes to core files, things would be easier if the changes were made automatically. Sometimes you can just include pre-edited files. But sometimes you don't want to replace commonly changed files (like header.tpl) with a customer version, just to add a link or a single line of code. The current discussion is the format of the script: XML, Text, or Patch file?
XML would be similar to how SMF creates plugins:
http://www.simplemachines.org/community ... c=299670.0
Code: Select all
<modification xmlns="http://www.simplemachines.org/xml/modification" xmlns:smf="http://www.simplemachines.org/">
<id>sium:postimage</id>
<version>1.1.0</version>
<file name="$themedir/Post.template.php">
<operation>
<search position="replace"><![CDATA[<textarea]]></search>
<add><![CDATA[ • <a href="javascript:void(0);" onclick="window.open(\'http://www.postimage.org/index.php?mode=smf&lang=english&forumurl=\' + escape(document.location.href), \'_imagehost\', \'resizable=yes,width=500,height=400\');return false;">Add image to post</a><br /><br /><textarea]]></add>
</operation>
</file>
</modification>
Text-based would be similar to how phpbb uses its community created EasyMod utility. Example:
Code: Select all
--- OPEN ---
catalog/controller/product/product.php
--- OPEN ---
--- FIND ---
$this->data['name'] = $product['name'];
--- FIND ---
--- REPLACE ---
$this->data['name'] = $product['name2'];
--- REPLACE ---
--- CLOSE ---
Patch-File would be based on linux patch files created from the "diff" application. Windows devs can also create patch files using the
GnuWin32 package that ports the "diff" command. This is the simplest as the file is created automatically for you simply by comparing 2 files and outputting the differences to a "patch" file. However, it is also the most complex as patch files aren't very human readable to the untrained eye.
Any other ideas are welcome.
Re: [OpenCart Package Installer] - Design Phase
Posted: Wed Feb 03, 2010 1:25 am
by i2Paq
I like the setup of your idea.
Like you said, SMF has the same idea, which not always work if the mod is not according to the standards.
Looking at your suggestion it means that some structural changes need to be made to the core.
Re: [OpenCart Package Installer] - Design Phase
Posted: Wed Feb 03, 2010 3:53 am
by Gerrit
I have three different hosting companies for my three websites. One is on a Windows 2003 server. They don't allow you to install such a script. Therefor the best solution in this case is XML.
I dont know how this is done in Drupal or other packages. The best way is like Debian handles this, search, click, silent download, silent install. Later you can maintanence this by an automic update feature.
The next thing is the language file. One language, English, or can you choose one?
Keep up the good work.
Re: [OpenCart Package Installer] - Design Phase
Posted: Wed Feb 03, 2010 4:12 am
by Qphoria
Not initially. The Phase I just needs to include the config.php and registry to be able to use the available methods... the rest of it is just file handling using php's own zip functions and file manipulation. Most of it should be able to be kept external.
Re: [OpenCart Package Installer] - Design Phase
Posted: Sat Mar 20, 2010 1:03 pm
by Qphoria
I've started working on this. I've decided that for now, I will use xml for the syntax and as there is no point in reinventing the wheel, I will use the exact same definition that SMF uses for its mods.
An example of an xml mod file that the installer will read and execute:
Code: Select all
<?xml version="1.0"?>
<modification>
<id>Mod Test by Qphoria</id>
<version>1.0</version>
<file name="index.php" error="fatal">
<operation>
<search position="after">
require_once('config.php');
</search>
<add><![CDATA[
//Q: Test line
]]></add>
<operation>
</file>
</modification>
That will search the index file for "require_once('config.php');"
If found, it will put the "//Q: Test line" on the line below it
If not found, it will throw an error and prevent or prompt installation based on the "error" value
(fatal, ignore, skip)