How to create a folder withing a setup script of custom Magento module? - magento

I am developing an extension, which can be installed by copying the extension folder into Magento folder. This extension includes a folder within Magento media folder, which should be writable by Magento. Since the folder can be copied with the rights different from the rights, which Magento runs on, I am looking for the way of creating this folder in the setup script.
It looks like a bad practice to me to run this code within the script for sql or entity setup. Is there any way in Magento to do such task in appropriate setup script or should I make the perfectionist in me shut up and simply put the code in the sql setup script?

if you want to create a folder for custom extension in magento use this code.
$customDir = Mage::getBaseDir('media').DS.'foldername';
$ioFile = new Varien_Io_File();
$ioFile->checkAndCreateFolder($customDir);

You can use Varien_Io_File::checkAndCreateFolder() to check and create directory not in setup script, but in the place of the actual usage of the folder.

I think it is not Magento-esque to create those folders in a setup script. It is more logical to just pack them with your extension and let the user put them in the correct place. Imho.
To make sure about the rights, you can test them in the code and produce an error message if incorrect, and make sure you mention it in the manual to the user.

Related

How to make msi block installing to ProgramFiles folder?

I made the msi package to allow the user to choose installation directory for the application.
I want the user to only download the application where it doesn't need read write permissions from the user, like %APP_DATA%/Roaming/my_app_example_name.
The reason being that the application has a self update mechanism and updates itself when it detects a new version on the server. The update itself doesn't use an msi launcher, it just downloads the new version of the app from the server using a http request, and replaces the old files.
.
.
For example, in the popular game spiral knights, they implemented this mechanism like this:
Here, you can see that the default installtation directory is the Appdata folder
If i change the installation directory to ProgramFiles, and try to install, I get this error :
It effectively blocks installation to the directory simply because it doesn't have permissions to create a folder from the installer itself, there.
I would like to implement the same mechanism, or something similar, because I think this is a very elegant solution to my problem. So any ideas on how to do this?
(By the way, I'm using jpackage to create the msi launchers)
You can use --win-per-user-install option with jpackage.
On Windows, the default is c:\Program Files\application-name; if the
--win-per-user-install option is used, the default is C:\Users\user-name\AppData\Local\application-name
More details on options at jpackage docs

How to reuse custom module with all in one installation in magento 1.9

I created a custom module that represents a custom payment method, the steps I follow are;
1) Create a module architecture in /app/local/NameSpace/MyModule
2) Create an xml file in /etc/modules to configure my module
3) Create templates /design/frontend/base/default/template/mymodule
The module works well, but i want to reuse the module in other projects with all in one installation. now, i want to know if i must develop a script to copy the xml file in /etc/modules and templates manually? or there is an existing solution in magento 1.9 to do this operation?
Thanks in advance,
You want to create a Magento Connect package. There's a UI for doing this under the System Magento menu (although the UI is sort of terrible) and some googling around should set you right. Once you have a connect package, you can install it into any system via the /downloader UI (also available via the System menu) or the ./mage CLI command.
Also -- if you choose "Magento Other" as the role for all your files, your resulting tgz archive can simply get uncompressed/unarchived into any Magento system's root folder. Also of interest -- my script for creating Connect Packages from raw tar archives.

Way to load locally developed magento extension

I am developing a magento extension. After getting help from stackoverflow, I am able to create a package extension which is stored in [magento]/var/connect folder. I noticed that package.xml, myextension.xml and myextension-1.0.0.0.1.tgz files are created therein.
I created another magento instance locally where I want to load that package and test. It's not possible to get my extension verified by magento team and then use it quickly or is it? I copied those package files under /var/connect of the test instance but I cannot see that appear in admin-> system -> magento connect -> package extensions.
Any idea how I can do that? All I need is he ability to let my customer have my zip files(package files), then they will upload somewhere. Any help would be appreciated.
You can upload packaged Magento extension by going to:
System > Magento Connect > Magento Connect Manager
then uploading the package under the Direct package file upload section.
Furthermore, if you decide not to package your extension, just copy the working file structure of your extension to it's own folder, and you can simply drop your extension files into the working root directory of compatibility Magento installs. Just be sure your extension file structures are correct. EX: app/code/local/MyNamespace/MyExtension etc.

How to make WIX create files to Program Files folder in the installation? I have "Access defined"

I am creating a WIX installer project. During one managed customized action, I need to create a file (other than the deployed files specified in the components of WIX) in the installation folder, which by default is the Program Files folder. I am experiencing the "Access denied" problem in Windows 7. After some searching, I found out that people say it is not advisable to create files into Program Files folder. Instead, try to create files into for example AppData folder. For example, see this link:
C# Access denied to path in a Windows Application
But my question is, the generated file is crucial to our SW, so it must reside in the installation folder. Isn't it the target of SW installation, I mean, to create file in most of the cases Program Files folder? Does it mean the only files should be added into installation folder, during the installation, are the deployed files (basically the targets of XCopy)?
My file can't be made deploy-able in the WIX, i.e, it can't be made ready before the installation. So what's the proper way or best practice to handle such situation: a file must be generated during the installation, into the installation folder. It is not some log file that I can put somewhere else. I tried to create a Permission element in WIX for the INSTALLADIR, although it seems to be against the rule mentioned in the link, but it still failed. Thanks!
UPDATE:
Based one MichaelUrman's commen, some more information. The generated file is needed after the SW is installed and necessary during normal launch of the SW. And I think it needs to be modified during normal use after the installation. And as I mentioned my a comment to #caveman_dick answer, my CA is actually in commit phase, I don't know whether there is any difference between it and normal deferred CA
Set the custom action to Execute="deferred", that will run the command elevated and should give it the required permissions to create the file.
Since you need to update that file from the main application, and I'm assuming your application does not require elevated privileges, you have three options.
The first is the worst: without a manifest, your executable's attempts to write to the Program Files folder will typically result in it being redirected to the Virtual Store (see File Virtualization). It sounds like this isn't happening in your case, so you can't use it.
The second option is to modify the application to store this in an appropriate location such as the ProgramData folder, or Common Documents, or (if appropriate) a per-user location under LocalAppData. This is typically the best approach, but has the highest development costs.
Finally the third option is to create the file and change its permissions (or in some cases to change the permissions on the folder containing the file), allowing limited users to modify this file. See LockPermissions or MsiLockPermissionsEx for the Windows Installer way to approach this. Change the permissions on as few files or folders, as restricted as possible, to keep the system as safe as possible if you go with this option.

How to change directory security attributes using InstallShield?

I'd like to change the security attribute of a directory that InstallShield creates under the CSIDL_COMMON_APPDATA - can someone please advise on how to do that during the installation process?
It's a script-defined folder.
Thank you.
Under InstallShield 2008 it's
Installation Designer > Components > [somecomponent] > Destination Permissions
Note that the directory properties are attached to the component, while individual File permissions are set under the 'Files' node
This assumes you are letting InstallShield / Windows Installer handle directory creation. If you're creating the directory in a script then things start getting tricky if you need to ensure a clean uninstall.
I think I found the answer for this - on this page: http://www.installsite.org/pages/en/isp_os.htm there's an ntperm.zip archive which contains a script that seems to do what I need.
you can also just easily call Windows commands "CACLS.EXE" or "ICACLS.EXE" -both are easy command line tool, e.g.
icacls file /grant Administrator:(D,WDAC)
- Will grant the user Administrator Delete and Write DAC
permissions to file
I don't know whether a Installshield builtin function exists for that. The simple solution is to create a DLL that does the real work of manipulating the security attributes and call it once the directory is created.
Typically, one might want to change the access so that everyone is able to read/write to the whole directory or file(s) within it.

Resources