-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from mothership-gmbh/#9_fix_observerstimes_for…
…_magento1.9.2.3 #9 fix observerstimes for magento1.9.2.3
- Loading branch information
Showing
19 changed files
with
614 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
66
src/lib/Mothership/Magerun/Patch/AbstractMagentoPatchFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
67 changes: 67 additions & 0 deletions
67
...run/modules/mothership_addons/src/Mothership/Magerun/Base/Command/Reports/HandlePatch.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
Oops, something went wrong.