2

I am creating a Joomla package that will install some plugins and some image files together. I want to copy the images from the package to the Joomla site using an installer script. How do I find the name of the temporary install directory in order to copy the files?

My pkg_foo.zip has the following directory structure.

packages/plg_plugin1.zip
packages/plg_plugin2.zip
image.png
pkg_foo.xml
script.php

And I have the following in script.php:

jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');

class pkg_fooInstallerScript
{
    function install($parent) {
            JFile::move( TEMPORARY_DIRECTORY . '/image.png', JPATH_ROOT . 'images/image.png';
        }
    }

}

How do I find the path to the temporary install directory?

3
  • 1
    I would suggest you install the images as part of the plugin, then copy from there after the installation, using the postflight() function – Lodder Feb 13 '17 at 11:00
  • I would prefer to copy from the temporary install directory. The reason being that the plugins I am installing are 3rd party. I don't want to edit the archives because any changes I make will be over-written if I update. Creating and installing a plugin for the sole purpose of holding the images before moving them doesn't seem correct either.The correct solution would be to copy the files from the package to the correct destination on installation. – Codewise Feb 13 '17 at 11:10
  • If I'm not mistaken, you can't get the temp directory during the install process. I think you misunderstood what I meant though, so I'll add an answer below – Lodder Feb 13 '17 at 11:15
1

You can use the postflight() function to move the images after the install() function has been executed and completed, like so:

class pkg_fooInstallerScript
{
    protected $extension = 'plg_myplugin';

    public function install($parent) 
    {
        // Do whatever you need to do when installing
    }

    public function postflight($type, $parent) 
    {
        // Only run the code if we're installing, not updating.
        if (strtolower($type) === 'install')
        {
            $imagePath = JPATH_SITE . '/plugins/' . $this->extension . '/images/image.png';
            $newPath   = JPATH_SITE . '/images/image.png';

            JFile::move($imagePath, $newPath;
        }
    }
}
0

To get the name of the temporary install directory from within the installer script - script.php, use this:

function install($parent)
{
    $temp_dir = $parent->getParent()->getPath('source');
}

and if you need it during updates, then place it in the update method.

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.