3

I was faced with this issue before and didn't find a "one size fits all" solution.
For an easier versioning I usually add content to a website using upgrade and data-upgrade scripts.
But I'm faced with an issue when my modules use resources that should go into the media folder and that's not versioned.
Let me give you an example.
I'm working on magento project that needs to have a slider on homepage. The code, no issue, I created a CRUD module that allows admin to manage the sliders and banners inside the sliders.
But the client already decided on the content for the slider for starters.
I don't want to manually add this content on each instance I deploy my module (staging, live, other developer's machines). I want everything to be replicated just by doing a git pull and a cache refresh.
So this should be easily done if I create a data-upgrade script, where I create an instance of my slider entity, a few instances of the banner entities and attach them to the slider.
Everything goes smoothly except that the banners should be placed in the media folder. That's not versioned (and should not be).
Any ideas on how I should handle this?

1

Maybe the AOE EnvSettingsTool is useful for you: https://github.com/AOEpeople/EnvSettingsTool

The original problem it solves is managing different settings for different systems (dev/test/staging/production) but "settings" is quite flexible, it also has a CopyFile handler, so you could store your media files outside the Magento root but in the repository and copy them over on deployment with the EnvSettingsTool.

For this task alone the tool is overkill but if you don't have another solution yet to handle different local.xml and database settings for different systems, give it a try.

  • +1 for the extension recommendation. Does not fit exactly my needs but with some work can be made to do what I need. In the mean time it seams that I found a simple solution: magento.stackexchange.com/a/43541/146 – Marius Nov 11 '14 at 13:01
0

Ultimately if you want everything to be prepared by just cloning/pulling the repository and clearing the cache then using the media directory just isn't feasible as it's always going to involve a manual step. As a compromise how about just having an extension specific images location under the base/default theme instead?

  • I thought of that, but it's not an option. In the example I gave, the banners can be added and deleted as the admin pleases. So they cannot be placed in the skin folder. Also allowing the module to use resourced from media and skin would complicated it for no reason. – Marius Nov 11 '14 at 12:41
0

It seams I can't see the forest because of the trees.
I have an idea, oddly because of this answer provided by myself :) .
You can basically do anything with the data install/upgrade scripts...including creating folders and writing files on the disk.
So my idea is to put those images somewhere (maybe even in the data folder or somewhere else) and in a data upgrade script, just copy these images in the media folder.
Simple as that.
I will post some code as soon as I write it.

[EDIT] Here is the code I use.
I placed the images I need inside the data/{resource_name}_setup folder.
The in my data-upgrade-1.0.0-1.0.1.php I have this:

//...some code here to initialize my models //then the actual upload:

$destinationFolder = Some logic to get the folder name; For example Mage::getBaseDir('media').DS.'slider';
//get the source image
$source = dirname(__FILE__).DS.'image.jpg';
//get the destination file name
$destinationFile = 'image.jpg';
$io = new Varien_Io_File();
//create folders in media if needed
$io->checkAndCreateFolder($destinationFolder);
//copy the file to the destination
$io->cp($source, $destinationFolder.DS.$destinationFile);
//set the image path to  my banner entity
$banner->setImage('/i/m/'.$destinationFile);
$banner->save();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.