Skip to content

Commit

Permalink
Merge branch 'release/5.2.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriarte-mendez committed Sep 20, 2018
2 parents 2cb672e + a2c80d6 commit ac6b005
Show file tree
Hide file tree
Showing 32 changed files with 282 additions and 182 deletions.
13 changes: 10 additions & 3 deletions Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
* @package RpayRatePAY
* @copyright Copyright (c) 2013 RatePAY GmbH (http://www.ratepay.com)
*/

use RpayRatePay\Component\Service\Logger;

require_once __DIR__ . '/Component/CSRFWhitelistAware.php';

class Shopware_Plugins_Frontend_RpayRatePay_Bootstrap extends Shopware_Components_Plugin_Bootstrap
Expand Down Expand Up @@ -67,7 +70,7 @@ public function getVersion()
if ($info) {
return $info['currentVersion'];
} else {
throw new Exception('The plugin has an invalid version file.');
throw new \Exception('The plugin has an invalid version file.');
}
}

Expand All @@ -83,7 +86,7 @@ public static function getPCConfig()
if ($info) {
return $info['payment_confirm'];
} else {
throw new Exception('The plugin has an invalid version file.');
throw new \Exception('The plugin has an invalid version file.');
}
}

Expand All @@ -109,6 +112,7 @@ public function getCapabilities()
*/
public function install()
{
Logger::singleton()->info('INSTALL Plugin Bootstrap');
$this->subscribeEvent('Enlight_Controller_Front_StartDispatch', 'onRegisterSubscriber');
$this->str = 'Shopware_Console_Add_Command';
$this->subscribeEvent('' . $this->str . '', 'onRegisterSubscriber');
Expand Down Expand Up @@ -147,6 +151,8 @@ public function install()
*/
public function update($version)
{

Logger::singleton()->info('UPDATE Plugin Bootstrap ' . $version);
$queue = [
new \RpayRatePay\Bootstrapping\FormsSetup($this),
new \RpayRatePay\Bootstrapping\DatabaseSetup($this),
Expand All @@ -163,7 +169,7 @@ public function update($version)
$bootstrapper->update();
}

\RpayRatePay\Component\Service\Logger::singleton()->addNotice('Successful module update');
Logger::singleton()->addNotice('Successful module update');

return [
'success' => true,
Expand Down Expand Up @@ -191,6 +197,7 @@ public function _dropOrderAdditionalAttributes()
*/
public function uninstall()
{
Logger::singleton()->info('UNINSTALL Plugin Bootstrap ');
$queue = [
new \RpayRatePay\Bootstrapping\DatabaseSetup($this),
];
Expand Down
4 changes: 2 additions & 2 deletions Bootstrapping/Bootstrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ abstract public function uninstall();
/**
* @param $configFile
* @return mixed
* @throws Exception
* @throws \Exception
*/
public function loadConfig($configFile)
{
if (!empty($configFile) && file_exists(__DIR__ . DIRECTORY_SEPARATOR . $configFile)) {
return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . $configFile), true);
}

throw new Exception("Unable to load configuration file '$configFile'");
throw new \Exception("Unable to load configuration file '$configFile'");
}

public function getName()
Expand Down
53 changes: 50 additions & 3 deletions Bootstrapping/CronjobSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@

namespace RpayRatePay\Bootstrapping;

use RpayRatePay\Component\Service\Logger;

class CronjobSetup extends Bootstrapper
{
const UPDATE_TRANSACTIONS_INTERVAL_SECONDS = 3600;
const UPDATE_TRANSACTIONS_ACTION = 'UpdateRatepayTransactions';
const LEGACY_TRANSACTIONS_ACTION = 'Shopware_CronJob_UpdateRatepayTransactions';

/**
* @throws Exception
*/
public function install()
{
$id = Shopware()->Db()->fetchOne('SELECT id from s_crontab WHERE `action` = ?', [self::UPDATE_TRANSACTIONS_ACTION]);
if ($id === false) {
$this->bootstrap->createCronJob('RatePAY Transaction Updater', self::UPDATE_TRANSACTIONS_ACTION, self::UPDATE_TRANSACTIONS_INTERVAL_SECONDS);
$settings = $this->getCronSettings();
$this->cleanUpLegacyCronjob();

if (!$this->hasStoredCronjobs()) {
$this->bootstrap->createCronJob(
'RatePAY Transaction Updater',
self::UPDATE_TRANSACTIONS_ACTION,
$settings['interval']
);
}
}

Expand All @@ -27,8 +36,46 @@ public function update()
$this->install();
}

/**
* @return array
*/
public function getCronSettings()
{
$row = Shopware()->Db()->fetchRow(
'SELECT `interval` FROM s_crontab WHERE `action` = ? ORDER BY id',
[self::LEGACY_TRANSACTIONS_ACTION]
);

return !empty($row) ? $row : [
'interval' => self::UPDATE_TRANSACTIONS_INTERVAL_SECONDS,
];
}

public function hasStoredCronjobs()
{
$id = Shopware()->Db()->fetchOne(
'SELECT `id` FROM s_crontab WHERE `action` = ? ORDER BY id',
[self::UPDATE_TRANSACTIONS_ACTION]
);

return !empty($id);
}

/**
* Remove all legacy cronjobs from table.
* Workaround to fix duplicated entries.
*/
public function cleanUpLegacyCronjob()
{
Shopware()->Db()->executeQuery(
'DELETE FROM s_crontab WHERE `action` = ?',
[self::LEGACY_TRANSACTIONS_ACTION]
);
}

/**
* @return mixed|void
* @throws \Zend_Db_Adapter_Exception
*/
public function uninstall()
{
Expand Down
4 changes: 2 additions & 2 deletions Bootstrapping/Database/CreateConfigInstallmentTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ protected function getQuery()
}

/**
* @param Enlight_Components_Db_Adapter_Pdo_Mysql $database
* @throws Zend_Db_Adapter_Exception
* @param \Enlight_Components_Db_Adapter_Pdo_Mysql $database
* @throws \Zend_Db_Adapter_Exception
*/
public function __invoke($database)
{
Expand Down
4 changes: 2 additions & 2 deletions Bootstrapping/Database/CreateConfigPaymentTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ protected function getQuery()
}

/**
* @param Enlight_Components_Db_Adapter_Pdo_Mysql $database
* @throws Zend_Db_Adapter_Exception
* @param \Enlight_Components_Db_Adapter_Pdo_Mysql $database
* @throws \Zend_Db_Adapter_Exception
*/
public function __invoke($database)
{
Expand Down
6 changes: 4 additions & 2 deletions Bootstrapping/Database/CreateConfigTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ protected function getQuery()
}

/**
* @param Enlight_Components_Db_Adapter_Pdo_Mysql $database
* @throws Zend_Db_Adapter_Exception
* @param \Enlight_Components_Db_Adapter_Pdo_Mysql $database
* @throws \Zend_Db_Adapter_Exception
*/
public function __invoke($database)
{
$database->query('DROP TABLE IF EXISTS `rpay_ratepay_config`');

$database->query($this->getQuery());

$hasColumnBackend = ShopwareUtil::tableHasColumn('rpay_ratepay_config', 'backend');
Expand Down
4 changes: 2 additions & 2 deletions Bootstrapping/Database/CreateLoggingTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ protected function getQuery()
}

/**
* @param Enlight_Components_Db_Adapter_Pdo_Mysql $database
* @throws Zend_Db_Adapter_Exception
* @param \Enlight_Components_Db_Adapter_Pdo_Mysql $database
* @throws \Zend_Db_Adapter_Exception
*/
public function __invoke($database)
{
Expand Down
4 changes: 2 additions & 2 deletions Bootstrapping/Database/CreateOrderHistoryTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ private function getQuery()
}

/**
* @param Enlight_Components_Db_Adapter_Pdo_Mysql $database
* @throws Zend_Db_Adapter_Exception
* @param \Enlight_Components_Db_Adapter_Pdo_Mysql $database
* @throws \Zend_Db_Adapter_Exception
*/
public function __invoke($database)
{
Expand Down
4 changes: 2 additions & 2 deletions Bootstrapping/Database/CreateOrderPositionsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ protected function getQuery()
}

/**
* @param Enlight_Components_Db_Adapter_Pdo_Mysql $database
* @throws Zend_Db_Adapter_Exception
* @param \Enlight_Components_Db_Adapter_Pdo_Mysql $database
* @throws \Zend_Db_Adapter_Exception
*/
public function __invoke($database)
{
Expand Down
4 changes: 2 additions & 2 deletions Bootstrapping/Database/CreateOrderShippingTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ protected function getQuery()
}

/**
* @param Enlight_Components_Db_Adapter_Pdo_Mysql $database
* @throws Zend_Db_Adapter_Exception
* @param \Enlight_Components_Db_Adapter_Pdo_Mysql $database
* @throws \Zend_Db_Adapter_Exception
*/
public function __invoke($database)
{
Expand Down
35 changes: 21 additions & 14 deletions Bootstrapping/DatabaseSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class DatabaseSetup extends Bootstrapper
{
/**
* @return mixed|void
* @throws Exception
* @throws \Exception
*/
public function install()
{
Expand All @@ -17,7 +17,7 @@ public function install()

/**
* @return mixed|void
* @throws Exception
* @throws \Exception
*/
public function update()
{
Expand All @@ -29,13 +29,13 @@ public function update()
* Drops all RatePAY database tables
*
* @return mixed|void
* @throws Exception
* @throws \Exception
*/
public function uninstall()
{
try {
//Shopware()->Db()->query("DROP TABLE IF EXISTS `rpay_ratepay_logging`");
//Shopware()->Db()->query("DROP TABLE IF EXISTS `rpay_ratepay_config`");
Shopware()->Db()->query("DROP TABLE IF EXISTS `rpay_ratepay_logging`");
Shopware()->Db()->query("DROP TABLE IF EXISTS `rpay_ratepay_config`");

/*
* These tables are not deleted. This makes possible to manage the
Expand All @@ -45,16 +45,17 @@ public function uninstall()
* Shopware()->Db()->query("DROP TABLE IF EXISTS `rpay_ratepay_order_shipping`");
*/

//Shopware()->Db()->query("DROP TABLE IF EXISTS `rpay_ratepay_order_history`");
//Shopware()->Db()->query("DROP TABLE IF EXISTS `rpay_ratepay_config_installment`");
//Shopware()->Db()->query("DROP TABLE IF EXISTS `rpay_ratepay_config_payment`");
} catch (Exception $exception) {
throw new Exception('Can not delete RatePAY tables - ' . $exception->getMessage());
Shopware()->Db()->query("DROP TABLE IF EXISTS `rpay_ratepay_order_history`");
Shopware()->Db()->query("DROP TABLE IF EXISTS `rpay_ratepay_config_installment`");
Shopware()->Db()->query("DROP TABLE IF EXISTS `rpay_ratepay_config_payment`");
} catch (\Exception $exception) {
throw new \Exception('Can not delete RatePAY tables - ' . $exception->getMessage());
}
}


/**
* @throws Exception
* @throws \Exception
*/
protected function createDatabaseTables()
{
Expand All @@ -74,10 +75,13 @@ protected function createDatabaseTables()
}
} catch (\Exception $exception) {
$this->bootstrap->uninstall();
throw new Exception('Can not create Database.' . $exception->getMessage());
throw new \Exception('Can not create Database.' . $exception->getMessage());
}
}

/**
* @throws \Exception
*/
private function updateConfigurationTables()
{
$tables = [
Expand All @@ -91,10 +95,13 @@ private function updateConfigurationTables()
$generator(Shopware()->Db());
}
} catch (\Exception $exception) {
throw new Exception('Can not update Database.' . $exception->getMessage());
throw new \Exception('Can not update Database.' . $exception->getMessage());
}
}

/**
* @throws \Exception
*/
private function removeSandboxColumns()
{
if (ShopwareUtil::tableHasColumn('s_core_config_elements', 'RatePaySandboxDE')) {
Expand All @@ -103,7 +110,7 @@ private function removeSandboxColumns()
"DELETE FROM `s_core_config_elements` WHERE `s_core_config_elements`.`name` LIKE 'RatePaySandbox%'"
);
} catch (\Exception $exception) {
throw new Exception("Can't remove Sandbox fields` - " . $exception->getMessage());
throw new \Exception("Can't remove Sandbox fields` - " . $exception->getMessage());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Bootstrapping/DeliveryStatusesSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class DeliveryStatusesSetup extends Bootstrapper
{
/**
* @throws Exception
* @throws \Exception
*/
public function install()
{
Expand All @@ -30,7 +30,7 @@ public function install()

/**
* @return mixed|void
* @throws Exception
* @throws \Exception
*/
public function update()
{
Expand Down
6 changes: 4 additions & 2 deletions Bootstrapping/Events/OrderOperationsSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static function getSubscribedEvents()
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
* @throws \Doctrine\ORM\TransactionRequiredException
* @throws \Exception
*/
public function beforeSaveOrderInBackend(\Enlight_Hook_HookArgs $arguments)
{
Expand All @@ -48,7 +49,7 @@ public function beforeSaveOrderInBackend(\Enlight_Hook_HookArgs $arguments)
) {
Logger::singleton()->addNotice('Bestellungen können nicht nachträglich auf RatePay Zahlungsmethoden geändert werden und RatePay Bestellungen können nicht nachträglich auf andere Zahlungsarten geändert werden.');
$arguments->stop();
throw new Exception('Bestellungen können nicht nachträglich auf RatePay Zahlungsmethoden geändert werden und RatePay Bestellungen können nicht nachträglich auf andere Zahlungsarten geändert werden.');
throw new \Exception('Bestellungen können nicht nachträglich auf RatePay Zahlungsmethoden geändert werden und RatePay Bestellungen können nicht nachträglich auf andere Zahlungsarten geändert werden.');
}

return false;
Expand Down Expand Up @@ -83,6 +84,7 @@ public function onBidirectionalSendOrderOperation(\Enlight_Hook_HookArgs $argume
* @throws \Doctrine\ORM\OptimisticLockException
* @throws \Doctrine\ORM\TransactionRequiredException
* @throws \Zend_Db_Adapter_Exception
* @throws \Exception
*/
public function afterOrderBatchProcess(\Enlight_Hook_HookArgs $arguments)
{
Expand All @@ -97,7 +99,7 @@ public function afterOrderBatchProcess(\Enlight_Hook_HookArgs $arguments)
$orders = $request->getParam('orders');

if (count($orders) < 1) {
throw new Exception('No order selected');
throw new \Exception('No order selected');
}

foreach ($orders as $order) {
Expand Down
Loading

0 comments on commit ac6b005

Please sign in to comment.