Skip to content

Commit

Permalink
Include PHP 5.3 support and improve release script, prepare for 1.0.6…
Browse files Browse the repository at this point in the history
… release
  • Loading branch information
petk committed Jun 3, 2016
1 parent 4cb12ba commit ae87264
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/README.html
/root/
/vendor/
/tests/files/
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ All notable changes to this project will be documented in this file. This projec
* ...


## [1.0.6] - 2016-06-03

### Added

* PHP 5.3 support
* Release script code improvements


## [1.0.5] - 2016-05-13

### Added
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ TinyMCE editor in Magento 1 is by default using English language. Slovenian
translation for TinyMCE is also enabled if you've followed one of the above
installation procedures.

**Which PHP versions are supported?**

This sl_SI language pack supports all of the latest PHP versions including 5.3.
Magento however [recommends](http://devdocs.magento.com/guides/m1x/system-requirements.html)
to use PHP 5.4 or PHP 5.5 for current shipping versions (1.9.x). Magento 1 works
fine also on PHP 7, however some minor [hacks](http://inchoo.net/magento/its-alive/)
are required. Consider upgrading your server to PHP 7.

**Which files/folders are included in the package?**

Language pack consists of the following files/folders:
Expand Down
8 changes: 8 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# TODO

* 1.0.6:
* Onemogočanje TinyMCE, če je glavni modul locale_sl_si onemogočen?
* adminhtml.csv: Kako je pravilno "Flat Catalog"

* TinyMCE nima prevedenega naslova popupa pri plugin-u "Insert variable"

19 changes: 19 additions & 0 deletions bin/check.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

$adminElements = array_map('str_getcsv', file(__DIR__.'/../package/app/locale/sl_SI/Mage_Adminhtml.csv'));

$admin = [];

foreach ($adminElements as $el) {
$admin[] = $el[0];
}

$csv = array_map('str_getcsv', file(__DIR__.'/../package/app/design/adminhtml/default/default/locale/sl_SI/translate.csv'));

$i = 1;
foreach($csv as $translate) {
if (!in_array($translate[0], $admin)) {
echo $i.'. '.$translate[0]."\n";
}
$i++;
}
30 changes: 30 additions & 0 deletions bin/checkDuplicates
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env php
<?php

require_once __DIR__ . '/../vendor/autoload.php';

function array_duplicates(array $array) {
return array_diff_assoc($array, array_unique($array));
}

try {
$files = scandir(__DIR__.'/../package/app/locale/sl_SI');
foreach ($files as $file) {
$translations = array_map('str_getcsv', file(__DIR__.'/../package/app/locale/sl_SI/'.$file));

$sources = [];
foreach ($translations as $translation) {
$sources[] = $translation[0];
}

$duplicates = array_duplicates($sources);
if (count($duplicates) !== 0) {
echo $file.":\n";
var_dump($duplicates);
}
}


} catch (\Exception $e) {
echo 'Exception: '.$e;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<config>
<modules>
<Slovenian_LocalePackSl>
<version>1.0.5</version>
<version>1.0.6</version>
</Slovenian_LocalePackSl>
</modules>
<adminhtml>
Expand Down
10 changes: 5 additions & 5 deletions package/package.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<package>
<name>locale_sl_si</name>
<version>1.0.5</version>
<version>1.0.6</version>
<stability>stable</stability>
<license uri="https://github.com/symfony-si/magento1-sl-si/blob/master/LICENSE">OSL-3.0</license>
<channel>community</channel>
Expand All @@ -10,8 +10,8 @@
<description>Slovenian (Slovenia) - sl_SI language pack for Magento 1.x Community Edition</description>
<notes>Slovenian translation files supporting Magento Community Editions up to 1.9.2.4. Translations include entire Magento Community edition - store's front end, administration, emails and TinyMCE editor in administration forms. Translations follow Slovenian grammar and translation rules from Lugos.</notes>
<authors><author><name>Peter Kokot</name><user>peterkokot</user><email>peterkokot@gmail.com</email></author></authors>
<date>2016-05-13</date>
<time>08:04:55</time>
<date>2016-06-03</date>
<time>13:10:39</time>
<contents>
<target name="magelocale">
<dir name="sl_SI">
Expand Down Expand Up @@ -135,7 +135,7 @@
<dir name="Slovenian">
<dir name="LocalePackSl">
<dir name="etc">
<file name="config.xml" hash="5016daa0389ce2ac16bfe1f4873533d1"/>
<file name="config.xml" hash="9646de674a56a1ca3771d9fd536373e3"/>
</dir>
</dir>
</dir>
Expand Down Expand Up @@ -252,5 +252,5 @@
</target>
</contents>
<compatible/>
<dependencies><required><php><min>5.4.0</min><max>8.0.0</max></php></required></dependencies>
<dependencies><required><php><min>5.2.0</min><max>8.0.0</max></php></required></dependencies>
</package>
12 changes: 8 additions & 4 deletions src/Archiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SymfonySi\LocalePack;


class Archiver
{
/**
Expand All @@ -25,17 +24,22 @@ class Archiver
*/
private $tmpName = 'package';

/**
* Archiver constructor.
*
* @param string $name
*/
public function __construct($name)
{
$this->name = $name;

$this->name = basename($name);
$this->rootDir = dirname($name);
}

/**
* Add file.
*
* @param string
* @param string $file
* @param string $fileInArchive
*/
public function addFile($file, $fileInArchive)
{
Expand Down
34 changes: 14 additions & 20 deletions src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ class Package
*/
private $packageDir;

/**
* @var string Project directory.
*/
private $rootDir;

/**
* @var array Output log messages
*/
Expand All @@ -50,7 +45,6 @@ public function __construct(array $config = [])
$this->configFile = $config['configFile'];
$this->packageFile = $config['packageFile'];
$this->packageDir = dirname($this->packageFile);
$this->rootDir = $this->packageDir.'/..';

// Set package name
$dom = new \DOMDocument;
Expand All @@ -75,12 +69,12 @@ public function build()
$archiver = new Archiver($this->name.'-'.$this->version.'.tgz');

// add all files defined in package.xml file
foreach($files as $file) {
$archiver->addFile($file, str_replace(realpath($this->packageDir), '', $file));
foreach ($files as $file) {
$archiver->addFile($file, str_replace($this->packageDir, '', $file));
}

// add package.xml
$archiver->addFile(realpath($this->packageFile), str_replace(realpath($this->packageDir), '', realpath($this->packageFile)));
$archiver->addFile($this->packageFile, str_replace($this->packageDir, '', $this->packageFile));

$archiver->compress();

Expand All @@ -94,7 +88,7 @@ public function build()
*/
private function patchConfigFile()
{
$dom = new \DOMDocument;
$dom = new \DOMDocument();
$dom->load($this->configFile);
$dom->getElementsByTagName('version')->item(0)->nodeValue = $this->version;
$dom->saveXML();
Expand All @@ -115,13 +109,13 @@ private function patchPackageFile()
$dom->load($this->packageFile);

$files = $dom->getElementsByTagName('file');
foreach($files as $file) {
$filePath = __DIR__.'/../package/'.$this->getFileFullPath($file);
foreach ($files as $file) {
$filePath = $this->packageDir.'/'.$this->getFilePath($file);

if (file_exists($filePath)) {
$md5 = md5_file($filePath);
$file->setAttribute('hash', $md5);
$filesInPackage[] = realpath($filePath);
$filesInPackage[] = $filePath;
} else {
$this->log[] = 'Warning: File '.basename($filePath).' not found.';
}
Expand All @@ -142,17 +136,17 @@ private function patchPackageFile()
}

/**
* Get file path for file from DoMNode.
* Get file path for file from DOMNode.
*
* @param \DOMNode
*
* @return string
*/
private function getFileFullPath(\DOMNode $file)
private function getFilePath(\DOMNode $file)
{
$curNode = $file->parentNode;
$filePath = $file->getAttribute('name');
while($curNode->nodeName == 'dir') {
while ($curNode->nodeName == 'dir') {
$filePath = $curNode->getAttribute('name').'/'.$filePath;
$curNode = $curNode->parentNode;
}
Expand All @@ -161,13 +155,13 @@ private function getFileFullPath(\DOMNode $file)
$targetDir = '';
if ($target == 'magecommunity') {
$targetDir = 'app/code/community';
} else if ($target == 'magedesign') {
} elseif ($target == 'magedesign') {
$targetDir = 'app/design';
} else if ($target == 'magelocale') {
} elseif ($target == 'magelocale') {
$targetDir = 'app/locale';
} else if ($target == 'mageetc') {
} elseif ($target == 'mageetc') {
$targetDir = 'app/etc';
} else if ($target == 'mageweb') {
} elseif ($target == 'mageweb') {
$targetDir = '';
}

Expand Down
30 changes: 30 additions & 0 deletions tests/ArchiverTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace SymfonySi\Test;

use SymfonySi\LocalePack\Archiver;

class ArchiverTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
if (!is_dir($folder = __DIR__.'/files')) {
mkdir($folder, 0777);
}

if (is_file($file = __DIR__.'/files/locale.tgz')) {
unlink($file);
}
}

public function testCompress()
{
$archiver = new Archiver(__DIR__.'/files/locale.tgz');

$archiver->addFile(__DIR__.'/Fixtures/package.xml', 'package.xml');

$archiver->compress();

$this->assertFileExists(__DIR__.'/files/locale.tgz');
}
}
17 changes: 9 additions & 8 deletions tests/PackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class PackageTest extends \PHPUnit_Framework_TestCase
public function setUp()
{
vfsStreamWrapper::register();
$root = new vfsStreamDirectory('myroot');
$root = new vfsStreamDirectory('root');
vfsStreamWrapper::setRoot($root);
vfsStream::copyFromFileSystem(__DIR__.'/../package', $root);
vfsStream::copyFromFileSystem(__DIR__.'/../package');

$this->config = [
'version' => '1.0.4',
'configFile' => vfsStream::url('myroot/app/code/community/Slovenian/LocalePackSl/etc/config.xml'),
'packageFile' => vfsStream::url('myroot/package.xml'),
'configFile' => vfsStream::url('root/app/code/community/Slovenian/LocalePackSl/etc/config.xml'),
'packageFile' => vfsStream::url('root/package.xml'),
];
}

Expand All @@ -40,8 +40,9 @@ public function testPatchConfigFile()
$obj = new Package($this->config);
$patchConfigFile->invoke($obj);


$this->assertContains(
'<version>1.0.4</version>', file_get_contents(vfsStream::url('myroot/app/code/community/Slovenian/LocalePackSl/etc/config.xml'))
'<version>1.0.4</version>', file_get_contents(vfsStream::url('root/app/code/community/Slovenian/LocalePackSl/etc/config.xml'))
);
}

Expand All @@ -50,7 +51,7 @@ public function testPatchPackageFile()
$patchPackageFile = self::getMethod('patchPackageFile');
$obj = new Package($this->config);
$patchPackageFile->invoke($obj);
$contents = file_get_contents(vfsStream::url('myroot/package.xml'));
$contents = file_get_contents(vfsStream::url('root/package.xml'));

$this->assertContains(
'<version>1.0.4</version>', $contents
Expand All @@ -68,7 +69,7 @@ public function testPatchPackageFile()
/**
* @dataProvider xmlProvider
*/
public function testGetFileFullPath($xml, $fileName, $expectedFilePath)
public function testGetFilePath($xml, $fileName, $expectedFilePath)
{
$dom = new \DOMDocument;
$dom->load($xml);
Expand All @@ -81,7 +82,7 @@ public function testGetFileFullPath($xml, $fileName, $expectedFilePath)
}
}

$method = self::getMethod('getFileFullPath');
$method = self::getMethod('getFilePath');
$obj = new Package($this->config);
$filePath = $method->invoke($obj, $nodeItem);
$this->assertEquals($filePath, $expectedFilePath);
Expand Down

0 comments on commit ae87264

Please sign in to comment.