Copying custom folder from install package - joomla

I created a component for joomla 3.2. It has a folder with framework files (folder name is forms). How can I transfer this folder to joomlaroot/libraries/ folder ?
Can this be done only using manifest file, or I need to use install.component.php file ? If yes, how can I specify path of 'forms' folder?
I guess I should use something like:
class com_ComponentInstallerScript
{
function install( $parent )
{
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
$target= 'forms';
$destination = JPATH_ROOT.'/libraries/';
JFolder::copy($target, $destination);
}
}

Here are the steps:
create a package which will contain the component that you already have
the library that you need to create. Read the article How To Package Joomla Libraries. Also here is a live example with the PHPExcel library for Joomla.

The Joomla installer has adapters for single files and for libraries, so what you would do is just package in that way. Then you can put your whole install package into a combined install.

Related

How to add a new vendor

I am new to prestashop and trying to add a 3rd party library in vendor folder which i could use in my custom module. I have added composer.json in my module as well but unable to get the 3rd party library installed in prestashop vendor folder.
Any help/guidance would be much appreciated.
I used the fzaninotto/faker library and I got it working like this :
Composer.json at the root of my module :
{
"require": {
"fzaninotto/faker": "^1.6"
}
}
then run
composer install
Now in order to use this package I created a file called faker.php at the root of my module that starts with including the correct files :
<?php
require('vendor/autoload.php');
require('../../config/config.inc.php');
$faker = Faker\Factory::create('fr_FR');
Basicly this is a 3 step process :
1. Create your composer.json
2. Run composer install
3. Include the autoload.php that is in the newly created vendor directory, make sure you use the correct relative path

Composer private package issue

I have created a private composer package in packagist.com but when I use
composer require command to fetch it. My package coming under vendor folder which is on root.
But I want it to be in app/code folder. Is there any parameter for composer.json where I can set app/code, so it will come under app/code/.
Yes there is. According to the composer documentation, if your project uses the PSR-4 specification for loading classes, then adding the snippet below to the composer.json file would work.
NB: You will need to change ProjectNameSpace to the base namespace for your project.
...
"autoload": {
"psr-4": {
"ProjectNameSpace\\": "app/code"
}
},
...
Theoretically. You can't composer will always place the code in vendor directory. The code is external and therefore can be updated only by composer. It must not be in app/code as only code you modify for the project should be in app/code.
If you wish to make a Magento project, you should have the fallowing files in the versioning tool.
app/*
composer.json
composer.lock
.htaccess
index.php
The other files will be handled by composer.
But if you really need to do it, but I don't see any reason to do so, then you could use a post-update & post-install script to move the code. But it's a very bad idea.

How to set custom folder path for sub folders in vendor when installing a package?

I want to install a package into my local project.For that I'm creating a composer.json file in my project folder is given below, it gives the total vendor folder of that package into my custom folder in my project. Its working fine.....
{
"config": {
"vendor-dir": "/var/www/html/Test2/Testing/Down"
},
}
It gives the package into 'Down' folder.
But, now I want the sub folders or files in that packages to be installed in my custom folders like js/css folders in my project.
For example i want jquery.js file into my local folder path
/var/www/html/Test2/Testing/assests/js
From the package "frameworks/jquery".
For that, what changes are needed in my composer.json file?
Composer is used to bring in packages to support the PHP code of a project, here is how they describe it on the Composer website:
Composer is a tool for dependency management in PHP. It allows you to
declare the libraries your project depends on and it will manage
(install/update) them for you.
In other words, if you need to do logging in your PHP code and decide to use the publicly available monolog package, you use composer to bring that package into your project, then in your PHP code, you can call monolog functions.
Using config to rename the vendor directory is trying to use Composer in a way that doesn't fit the intent of the tool. The vendor directory is used to hold the packages brought in (such as the monolog code). The vendor-dir value is simply renaming that directory.
Since you have GitHub listed as a tag, you could possibly use cloning to get your files to your website directory.
I've modified my composer.json file, it looks like the below:
{
"config": {
"vendor-dir": "/var/www/html/Test2/Testing/Down"
},
"require": {
},
"scripts": {
"post-package-install": [
"php -r \"exec('cp -r /var/www/html/Test2/Testing/Down/frameworks/jquery/* /var/www/html/Test2/Testing/assets/js');\""
]
}
}
It will gives all selected files in a package to my local folder.
Briefly the files in the folder 'frameworks/jquery' are copied into my local 'assets/js' folder.

Extract file name from a particular folder and use it to get some other information

I have a libs folder, there I have few jar files. There names are like this - componentName + version.jar. There is in all 4 files in libs folder. Now I need the component names from these files and I want to use it for some other purpose. How can I get that in gradle. My jar files in libs folder are : bo-1.0.0.jar, so-2.2.1.jar, do-1.0.1.jar and fz-1.0.1.jar
I want to get bo,so,do,fz in variables component_bo,component_so,component_do,component_fz.
You can just list the contents of that folder and do some simple string manipulation. Here's an example of a pretty naive implementation but I think you can get the idea.
def components = fileTree('libs').collect { it.name.split('-')[0] }
components.each { component ->
// do something
}

Automatically create new folder under images on module installation

Is it possible for a Joomla extension to automatically create a folder (event) under images -> /images/events/ when the user installs the extension inside Joomla Administrator ?
Inside your component's xml file you will need to add in the following attribute:
<installfile>install.componentname.php</installfile>
replace with the name of your component, this can be added just underneath the description attribute of your components install xml file.
Once this has been added you will need to create a file called "install.componentname.php", again replace componentname with the name of your component.
Inside this file add the following:
<?php
// no direct access
defined('_JEXEC') or die('Restricted Access');
// import joomla's filesystem classes
jimport('joomla.filesystem.folder');
// create a folder inside your images folder
if(JFolder::create(JPATH_ROOT.DS.'images'.DS.'events')) {
echo "Folder created successfully";
} else {
echo "Unable to create folder";
} ?>
Package this up and install, the install..php file should be at the top level of your zip archive. Lastly you will need to add this file to your components file list, just after the attribute add the following line:
<files>
<filename>install.componentname.php</filename>
</files>
If the folder is created successfully, it will say Folder created successfully.
you can specify a custom php script to be run at extension installation in your extension's manifest file [1, 2]. this script could create your folder /images/events/.
there are some differences in the installer between joomla 1.5 and 1.6:
1.5
you can only do this for components, not for modules or plugins
to specify your custom script, you use the <installfile/> section of the manifest file
1.6
besides for components, you can use a custom install script for modules and plugins, too
use the <scriptfile/> section of the manifest file
[...] i see another answer has been posted. have a look at it for 1.5; for 1.6, use <scriptfile/> and have a look at http://docs.joomla.org/Developers , especially http://docs.joomla.org/How_to_use_the_filesystem_package . the actual creation of the folder is left as an exercise for the reader.
<!-- Site Main Media File Copy Section -->
<media destination="com_helloworld">
<filename>image.png</filename>
<filename>flash.swf</filename>
</media>
http://docs.joomla.org/Components:xml_installfile

Resources