Skip to content

Commit

Permalink
Merge pull request #31 from mothership-gmbh/#9_fix_observerstimes_for…
Browse files Browse the repository at this point in the history
…_magento1.9.2.3

#9 fix observerstimes for magento1.9.2.3
  • Loading branch information
azngeek committed Mar 3, 2016
2 parents 5f17e60 + 6dc8183 commit 56ac664
Show file tree
Hide file tree
Showing 19 changed files with 614 additions and 92 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.gitignore
src/app/etc/mothership/environments/environment_vm.php
src/app/etc/mothership/environments/environment_live.php
src/app/etc/mothership/environments/environment_live.php
/vendor/
92 changes: 92 additions & 0 deletions src/lib/Mothership/Magerun/Patch/AbstractMagentoPatch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* This file is part of the Mothership GmbH code.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mothership\Magerun\Patch;

/**
* Class AbstractMagentoPatch
*
* @category Mothership
* @package Mothership_Magerun_Addons
* @author Maurizio Brioschi <[email protected]>
* @copyright 2016 Mothership Gmbh
* @link http://www.mothership.de/
*/
abstract class AbstractMagentoPatch implements PatchInterface
{
protected $pathDir;

protected $magento_root;
protected $mage_php; //Mage.php original file from magento
protected $app_php; //App.php original file from Magento

public function __construct()
{
$this->pathDir = $this->setPathDirectory();
}

/**
* add the patch
*
* @param $magentoRoot
*
* @return void
*/
function addPatch($magentoRoot)
{
$this->storeOriginalFilesPatched($magentoRoot);
}

/**
* remove patch
*
* @return void
*
* @throws \Exception
*/
function removePatch()
{
if (is_null($this->magento_root)) {
throw new \Exception("Patch is not added to Magento yet");
}

file_put_contents($this->magento_root . "/app/Mage.php", $this->mage_php);
file_put_contents($this->magento_root . "/app/code/core/Mage/Core/Model/App.php", $this->app_php);
}

/**
* Store original files content before to add the patch
*
* @param $magentoRoot
*
* @throws \Exception
*/
protected function storeOriginalFilesPatched($magentoRoot)
{
$this->magento_root = $magentoRoot;

if (!file_exists($this->magento_root . "/app/Mage.php")) {
throw new \Exception($this->magento_root . "/app/Mage.php doesn't exist");
}

if (!file_exists($this->magento_root . "/app/code/core/Mage/Core/Model/App.php")) {
throw new \Exception($this->magento_root . "/app/code/core/Mage/Core/Model/App.php doesn't exist");
}

$this->magento_root = $magentoRoot;
$this->mage_php = file_get_contents($this->magento_root . '/app/Mage.php');
$this->app_php = file_get_contents($this->magento_root . "/app/code/core/Mage/Core/Model/App.php");

}

/**
* Set the path directory of the patch
*
* @return void
*/
abstract protected function setPathDirectory();
}
66 changes: 66 additions & 0 deletions src/lib/Mothership/Magerun/Patch/AbstractMagentoPatchFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* This file is part of the Mothership GmbH code.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mothership\Magerun\Patch;
/**
* Class AbstractMagentoPatchFactory
*
* @category Mothership
* @package Mothership_Magerun_Addons
* @author Maurizio Brioschi <[email protected]>
* @copyright 2016 Mothership Gmbh
* @link http://www.mothership.de/
*/
abstract class AbstractMagentoPatchFactory
{
/**
* @var string (ex. 1.9.2.3)
*/
protected $magentoVersion;
/**
* the patch to apply
*
* @var PatchInterface
*/
protected $patch;

/**
* AbstractMagentoPatchFactory constructor.
*
* @param $magentoV
*/
public function __construct($magentoV)
{
$this->magentoVersion = $magentoV;
}

/**
* Get the class for the patch, in base of the Magento version
*
* @return void
*
* @throws \Exception if the patch is not set
*/
abstract protected function setMagentoPatchClass();

/**
*
* @return mixed
*
* @throws \Exception
*/
public function getPatch()
{
try {
$this->setMagentoPatchClass();
return $this->patch;
} catch (\Exception $e) {
throw $e;
}

}
}
37 changes: 37 additions & 0 deletions src/lib/Mothership/Magerun/Patch/PatchInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* This file is part of the Mothership GmbH code.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mothership\Magerun\Patch;
/**
* Class AbstractPatch
*
* @category Mothership
* @package Mothership_Magerun_Addons
* @author Maurizio Brioschi <[email protected]>
* @copyright 2016 Mothership Gmbh
* @link http://www.mothership.de/
*/
Interface PatchInterface
{
/**
* add the patch
*
* @param $magentoRoot
*
* @return void
*/
function addPatch($magentoRoot);

/**
* remove patch
*
* @return void
*/
function removePatch();

}

75 changes: 75 additions & 0 deletions src/lib/Mothership/Magerun/Signal/AbstractHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* This file is part of the Mothership GmbH code.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mothership\Magerun\Signal;

use Symfony\Component\Console\Output\OutputInterface;

/**
* Class AbstractHandler
*
* Handle signal from the command line
*
* @category Mothership
* @package Mothership_Magerun_Addons
* @author Maurizio Brioschi <[email protected]>
* @copyright 2016 Mothership Gmbh
* @link http://www.mothership.de/
*/
abstract class AbstractHandler implements HandleInterface
{
/**
* Output to the command line
*
* @var OutputInterface
*/
protected $output;

/**
* Handler constructor.
*
* @param OutputInterface $output
*/
public function __construct(OutputInterface $output)
{
$this->output = $output;

declare(ticks = 1);

$this->run();
}

/**
* Handle the signal from the terminal
*
* @return void
*/
public function run()
{
$this->configureSignals();
}

/**
* Wait $seconds for the term signal (SIGTERM)
*
* @param int $seconds
*
* @return void
*/
public function waitForTermSignal($seconds = 1)
{
$info = [];
pcntl_sigtimedwait(array(SIGTERM), $info, $seconds);
}

/**
* Signal to handle
*
* @return void
*/
abstract public function configureSignals();
}
32 changes: 32 additions & 0 deletions src/lib/Mothership/Magerun/Signal/HandleInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* This file is part of the Mothership GmbH code.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mothership\Magerun\Signal;
/**
* Class HandleInterface
*
* @category Mothership
* @package Mothership_Magerun_Addons
* @author Maurizio Brioschi <[email protected]>
* @copyright 2016 Mothership Gmbh
* @link http://www.mothership.de/
*/
interface HandleInterface
{
/**
* Start the handler
* @return void
*/
function run();

/**
* action done when stop handle
*
* @return void
*/
function stop();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* This file is part of the Mothership GmbH code.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mothership\Magerun\Base\Command\Reports;

use Mothership\Magerun\Patch\PatchInterface;
use Mothership\Magerun\Signal\AbstractHandler;

/**
* Class HandleBasics
* Handle for patch
*
* @category Mothership
* @package Mothership_Magerun_Addons
* @author Maurizio Brioschi <[email protected]>
* @copyright 2016 Mothership Gmbh
* @link http://www.mothership.de/
*/
class HandlePatch extends AbstractHandler
{
protected $patch;

public function __construct(OutputInterface $output, PatchInterface $patch)
{
parent::__construct($output);
if(is_null($patch)){
throw new \Exception("Patch class can't be null");
}
$this->patch = $patch;
}

/**
* Signal to handle
*
* @return void
*/
public function configureSignals()
{
pcntl_signal(SIGINT, function ($signal) {
$this->output->writeln("<info>Handle signal: " . $signal . "</info>");
$this->stop();
});

pcntl_signal(SIGTSTP, function ($signal) {
$this->output->writeln("<info>Handle signal: " . $signal . "</info>");
$this->stop();
});
}

/**
* action done when stop handle
*
* @return void
*/
public function stop()
{
$this->output->writeln("<info>Removing patch</info>");
$this->patch->removePatch();
$this->output->writeln("<info>Stop reporting</info>");
exit;
}
}

Loading

0 comments on commit 56ac664

Please sign in to comment.