Skip to content

Commit

Permalink
Use the Archive package from framework and deprecate JArchive (joomla…
Browse files Browse the repository at this point in the history
…#14157)

* Add archive package

* Deprecate JArchive

* Deprecate JArchive

* Use the Archive class instead of JArchive

* Wrong indents

* Wrong indents second part

* Setting tmp path correct

* adapt the extract dir based on file extension

* remove debug code

* Use the latest code from the archive class till version 1.1.5 is released

* Revert workaround

* Adapt installer

* Use the archive

* Deprecate the adapters

* CS

* CS

* CS

* CS

* Use version 1.1.5

* zero 24 cs
  • Loading branch information
laoneo authored and mbabker committed Jun 26, 2017
1 parent 6379ae8 commit 621a087
Show file tree
Hide file tree
Showing 36 changed files with 8,277 additions and 138 deletions.
6 changes: 5 additions & 1 deletion administrator/components/com_banners/models/tracks.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

defined('_JEXEC') or die;

use \Joomla\Archive\Archive;

JLoader::register('BannersHelper', JPATH_ADMINISTRATOR . '/components/com_banners/helpers/banners.php');

/**
Expand Down Expand Up @@ -516,7 +518,9 @@ public function getContent()
}
}

if (!$packager = JArchive::getAdapter('zip'))
$archive = new Archive;

if (!$packager = $archive->getAdapter('zip'))
{
$this->setError(JText::_('COM_BANNERS_ERR_ZIP_ADAPTER_FAILURE'));

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"require": {
"php": ">=5.3.10",
"joomla/application": "~1.5",
"joomla/archive": "~1.1.5",
"joomla/data": "~1.2",
"joomla/di": "~1.2",
"joomla/event": "~1.1",
Expand Down
103 changes: 102 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

136 changes: 10 additions & 126 deletions libraries/joomla/archive/archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');

use Joomla\Archive\Archive;

/**
* An Archive handling class
*
* @since 11.1
* @since 11.1
* @deprecated 4.0 use the Joomla\Archive\Archive class instead
*/
class JArchive
{
Expand All @@ -35,135 +38,15 @@ class JArchive
*
* @since 11.1
* @throws InvalidArgumentException
* @deprecated 4.0 use the Joomla\Archive\Archive class instead
*/
public static function extract($archivename, $extractdir)
{
$untar = false;
$result = false;
$ext = JFile::getExt(strtolower($archivename));

// Check if a tar is embedded...gzip/bzip2 can just be plain files!
if (JFile::getExt(JFile::stripExt(strtolower($archivename))) == 'tar')
{
$untar = true;
}

switch ($ext)
{
case 'zip':
$adapter = self::getAdapter('zip');

if ($adapter)
{
$result = $adapter->extract($archivename, $extractdir);
}
break;

case 'tar':
$adapter = self::getAdapter('tar');

if ($adapter)
{
$result = $adapter->extract($archivename, $extractdir);
}
break;

case 'tgz':
// This format is a tarball gzip'd
$untar = true;

case 'gz':
case 'gzip':
// This may just be an individual file (e.g. sql script)
$adapter = self::getAdapter('gzip');

if ($adapter)
{
$config = JFactory::getConfig();
$tmpfname = $config->get('tmp_path') . '/' . uniqid('gzip');
$gzresult = $adapter->extract($archivename, $tmpfname);

if ($gzresult instanceof Exception)
{
@unlink($tmpfname);

return false;
}

if ($untar)
{
// Try to untar the file
$tadapter = self::getAdapter('tar');

if ($tadapter)
{
$result = $tadapter->extract($tmpfname, $extractdir);
}
}
else
{
$path = JPath::clean($extractdir);
JFolder::create($path);
$result = JFile::copy($tmpfname, $path . '/' . JFile::stripExt(basename(strtolower($archivename))), null, 1);
}

@unlink($tmpfname);
}
break;

case 'tbz2':
// This format is a tarball bzip2'd
$untar = true;

case 'bz2':
case 'bzip2':
// This may just be an individual file (e.g. sql script)
$adapter = self::getAdapter('bzip2');

if ($adapter)
{
$config = JFactory::getConfig();
$tmpfname = $config->get('tmp_path') . '/' . uniqid('bzip2');
$bzresult = $adapter->extract($archivename, $tmpfname);

if ($bzresult instanceof Exception)
{
@unlink($tmpfname);

return false;
}

if ($untar)
{
// Try to untar the file
$tadapter = self::getAdapter('tar');

if ($tadapter)
{
$result = $tadapter->extract($tmpfname, $extractdir);
}
}
else
{
$path = JPath::clean($extractdir);
JFolder::create($path);
$result = JFile::copy($tmpfname, $path . '/' . JFile::stripExt(basename(strtolower($archivename))), null, 1);
}

@unlink($tmpfname);
}
break;

default:
throw new InvalidArgumentException('Unknown Archive Type');
}

if (!$result || $result instanceof Exception)
{
return false;
}
// The archive instance
$archive = new Archive(array('tmp_path' => JFactory::getConfig()->get('tmp_path')));

return true;
// Extract the archive
return $archive->extract($archivename, $extractdir);
}

/**
Expand All @@ -175,6 +58,7 @@ public static function extract($archivename, $extractdir)
*
* @since 11.1
* @throws UnexpectedValueException
* @deprecated 4.0 use the Joomla\Archive\Archive class instead
*/
public static function getAdapter($type)
{
Expand Down
3 changes: 2 additions & 1 deletion libraries/joomla/archive/bzip2.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
/**
* Bzip2 format adapter for the JArchive class
*
* @since 11.1
* @since 11.1
* @deprecated 4.0 use the Joomla\Archive\Bzip2 class instead
*/
class JArchiveBzip2 implements JArchiveExtractable
{
Expand Down
3 changes: 2 additions & 1 deletion libraries/joomla/archive/extractable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
/**
* Archieve class interface
*
* @since 12.1
* @since 12.1
* @deprecated 4.0 use the Joomla\Archive\ExtractableInterface interface instead
*/
interface JArchiveExtractable
{
Expand Down
3 changes: 2 additions & 1 deletion libraries/joomla/archive/gzip.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
* @contributor Michael Slusarz <[email protected]>
* @contributor Michael Cochrane <[email protected]>
*
* @since 11.1
* @since 11.1
* @deprecated 4.0 use the Joomla\Archive\Gzip class instead
*/
class JArchiveGzip implements JArchiveExtractable
{
Expand Down
3 changes: 2 additions & 1 deletion libraries/joomla/archive/tar.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @contributor Michael Slusarz <[email protected]>
* @contributor Michael Cochrane <[email protected]>
*
* @since 11.1
* @since 11.1
* @deprecated 4.0 use the Joomla\Archive\Tar class instead
*/
class JArchiveTar implements JArchiveExtractable
{
Expand Down
3 changes: 3 additions & 0 deletions libraries/joomla/archive/wrapper/archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @package Joomla.Platform
* @subpackage Archive
* @since 3.4
* @deprecated 4.0 use the Joomla\Archive\Archive class instead
*/
class JArchiveWrapperArchive
{
Expand All @@ -29,6 +30,7 @@ class JArchiveWrapperArchive
* @see JArchive::extract()
* @since 3.4
* @throws InvalidArgumentException
* @deprecated 4.0 use the Joomla\Archive\Archive class instead
*/
public function extract($archivename, $extractdir)
{
Expand All @@ -44,6 +46,7 @@ public function extract($archivename, $extractdir)
*
* @see JUserHelper::getAdapter()
* @since 3.4
* @deprecated 4.0 use the Joomla\Archive\Archive class instead
*/
public function getAdapter($type)
{
Expand Down
3 changes: 2 additions & 1 deletion libraries/joomla/archive/zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
* @contributor Michael Slusarz <[email protected]>
* @contributor Michael Cochrane <[email protected]>
*
* @since 11.1
* @since 11.1
* @deprecated 4.0 use the Joomla\Archive\Zip class instead
*/
class JArchiveZip implements JArchiveExtractable
{
Expand Down
Loading

0 comments on commit 621a087

Please sign in to comment.