Skip to content
This repository was archived by the owner on Mar 17, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
0 README.rst → Readme.md
100755 → 100644
File renamed without changes.
246 changes: 123 additions & 123 deletions classes/PayplugLock.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* 2013 - 2014 PayPlug SAS
* 2013 - 2015 PayPlug SAS
*
* NOTICE OF LICENSE
*
Expand All @@ -19,138 +19,138 @@
* needs please refer to http://www.prestashop.com for more information.
*
* @author PayPlug SAS
* @copyright 2013 - 2014 PayPlug SAS
* @copyright 2013 - 2015 PayPlug SAS
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PayPlug SAS
*/

if (!defined('_PS_VERSION_'))
die(header('HTTP/1.0 404 Not Found'));
if (!defined('_PS_VERSION_')) {
die(header('HTTP/1.0 404 Not Found'));
}

/**
* Description of totRules
*
* @author 202-ecommerce
*/
class PayplugLock extends ObjectModel {

const MAX_CHECK_TIME = 5;

public static $definition;

public $id_payplug_lock;
public $id_cart;
public $date_add;
public $date_upd;

protected $table = 'payplug_lock';
protected $identifier = 'id_payplug_lock';
protected $fieldsRequired = array(
'id_cart'
);
protected $fieldsValidate = array(
'id_cart' => 'isInt'
);
protected $fieldsValidateLang = array(
);

public function __construct($id = false, $id_lang = false)
{
parent::__construct($id, $id_lang);
class PayplugLock extends ObjectModel
{
const MAX_CHECK_TIME = 5;

public static $definition;

public $id_payplug_lock;
public $id_cart;
public $date_add;
public $date_upd;

protected $table = 'payplug_lock';
protected $identifier = 'id_payplug_lock';
protected $fieldsRequired = array(
'id_cart'
);
protected $fieldsValidate = array(
'id_cart' => 'isInt'
);
protected $fieldsValidateLang = array(
);

public function __construct($id = false, $id_lang = false)
{
parent::__construct($id, $id_lang);

self::$definition = array(
'table' => $this->table,
'primary' => $this->identifier,
'fields' => array(
'id_cart' => array('type' => self::TYPE_STRING, 'validate' => 'isInt'),
),
);
}

/**
* Check
* @param integer $id_cart Cart identifier
* @return boolean if locked
*/
public static function check($id_cart, $loop_time = 1)
{
$locked = false;

$time = 0;

while (($locked = self::exists($id_cart)) && $time < PayplugLock::MAX_CHECK_TIME)
{
if (function_exists('usleep'))
usleep($loop_time * 1000000);
else
self::usleep($loop_time * 1000);

$time++;
}
}

/**
* Check if exists
* @param integer $id_cart Cart identifier
* @return boolean If exists
*/
public static function exists($id_cart)
{
$lock = self::getInstanceByCart((int)$id_cart);

return Validate::isLoadedObject($lock);
}

/**
* Set instance of PayplugLock
* @param integer $id_cart Cart identifier
* @return \PayplugLock Instance
*/
public static function getInstanceByCart($id_cart)
{
$query = 'SELECT `id_payplug_lock`
FROM `'._DB_PREFIX_.'payplug_lock`
WHERE `id_cart` = '.(int)$id_cart.' ';

return new PayplugLock((int)Db::getInstance()->getValue($query));
}

/**
* Create lock
* @param integer $id_cart Cart identifier
* @return boolean Create successfull
*/
public static function addLock($id_cart)
{
$lock = new PayplugLock();
$lock->id_cart = (int)$id_cart;

return $lock->save();
}

/**
* Delete lock
* @param integer $id_cart Cart identifier
* @return boolean Delete successfull
*/
public static function deleteLock($id_cart)
{
$lock = self::getInstanceByCart((int)$id_cart);

return $lock->delete();
}

/**
* Sleep time
*/
private static function usleep($seconds)
{
$start = microtime();

do
{
// Wait !
$current = microtime();
} while (($current - $start) < $seconds);
}
'table' => $this->table,
'primary' => $this->identifier,
'fields' => array(
'id_cart' => array('type' => self::TYPE_STRING, 'validate' => 'isInt'),
),
);
}

/**
* Check
* @param integer $id_cart Cart identifier
* @return boolean if locked
*/
public static function check($id_cart, $loop_time = 1)
{
$locked = false;

$time = 0;

while (($locked = self::exists($id_cart)) && $time < PayplugLock::MAX_CHECK_TIME) {
if (function_exists('usleep')) {
usleep($loop_time * 1000000);
} else {
self::usleep($loop_time * 1000);
}

$time++;
}
}

/**
* Check if exists
* @param integer $id_cart Cart identifier
* @return boolean If exists
*/
public static function exists($id_cart)
{
$lock = self::getInstanceByCart((int)$id_cart);

return Validate::isLoadedObject($lock);
}

/**
* Set instance of PayplugLock
* @param integer $id_cart Cart identifier
* @return \PayplugLock Instance
*/
public static function getInstanceByCart($id_cart)
{
$query = 'SELECT `id_payplug_lock`
FROM `'._DB_PREFIX_.'payplug_lock`
WHERE `id_cart` = '.(int)$id_cart.' ';

return new PayplugLock((int)Db::getInstance()->getValue($query));
}

/**
* Create lock
* @param integer $id_cart Cart identifier
* @return boolean Create successfull
*/
public static function addLock($id_cart)
{
$lock = new PayplugLock();
$lock->id_cart = (int)$id_cart;

return $lock->save();
}

/**
* Delete lock
* @param integer $id_cart Cart identifier
* @return boolean Delete successfull
*/
public static function deleteLock($id_cart)
{
$lock = self::getInstanceByCart((int)$id_cart);

return $lock->delete();
}

/**
* Sleep time
*/
private static function usleep($seconds)
{
$start = microtime();

do {
// Wait !
$current = microtime();
} while (($current - $start) < $seconds);
}
}
10 changes: 5 additions & 5 deletions classes/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* 2013 - 2014 PayPlug SAS
* 2013 - 2015 PayPlug SAS
*
* NOTICE OF LICENSE
*
Expand All @@ -19,17 +19,17 @@
* needs please refer to http://www.prestashop.com for more information.
*
* @author PayPlug SAS
* @copyright 2013 - 2014 PayPlug SAS
* @copyright 2013 - 2015 PayPlug SAS
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PayPlug SAS
*/

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");

header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

header("Location: ../../../../");
exit;
exit;
10 changes: 5 additions & 5 deletions controllers/front/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* 2013 - 2014 PayPlug SAS
* 2013 - 2015 PayPlug SAS
*
* NOTICE OF LICENSE
*
Expand All @@ -19,17 +19,17 @@
* needs please refer to http://www.prestashop.com for more information.
*
* @author PayPlug SAS
* @copyright 2013 - 2014 PayPlug SAS
* @copyright 2013 - 2015 PayPlug SAS
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PayPlug SAS
*/

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");

header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

header("Location: ../../../../");
exit;
exit;
Loading