120 lines
2.3 KiB
PHP
120 lines
2.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* File from http://PrestaShow.pl
|
|
*
|
|
* DISCLAIMER
|
|
* Do not edit or add to this file if you wish to upgrade this module to newer
|
|
* versions in the future.
|
|
*
|
|
* @authors PrestaShow.pl <kontakt@prestashow.pl>
|
|
* @copyright 2015 PrestaShow.pl
|
|
* @license http://PrestaShow.pl/license
|
|
*/
|
|
class PShow_Queue
|
|
{
|
|
|
|
/**
|
|
* Path to database file
|
|
*
|
|
* @var string
|
|
*/
|
|
private $database_filepath;
|
|
|
|
/**
|
|
* Array of filenames
|
|
*
|
|
* @var array
|
|
*/
|
|
private $queue = array();
|
|
|
|
/**
|
|
* @var PShow_Queue
|
|
*/
|
|
private static $instance = null;
|
|
|
|
/**
|
|
* @return PShow_Queue
|
|
*/
|
|
public static function getInstance()
|
|
{
|
|
if (self::$instance === null) {
|
|
self::$instance = new PShow_Queue();
|
|
}
|
|
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* Constructor - get queue from file
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->database_filepath = getModulePath(__FILE__) . 'import-queue';
|
|
|
|
if (file_exists($this->database_filepath)) {
|
|
$this->queue = file($this->database_filepath);
|
|
|
|
foreach ($this->queue as &$q)
|
|
$q = str_replace(array("\n", "\s", "\t"), null, $q);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Destructor - save queue to file
|
|
*/
|
|
public function __destruct()
|
|
{
|
|
$this->saveToFile();
|
|
}
|
|
|
|
/**
|
|
* Save queue to file
|
|
*/
|
|
public function saveToFile()
|
|
{
|
|
file_put_contents($this->database_filepath, implode("\n", array_map('trim', $this->queue)));
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getQueue()
|
|
{
|
|
return $this->queue;
|
|
}
|
|
|
|
/**
|
|
* Get first element from queue
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getFromQueue()
|
|
{
|
|
return array_shift($this->queue);
|
|
}
|
|
|
|
/**
|
|
* Add element to the end of queue
|
|
*
|
|
* @param string $filename
|
|
*/
|
|
public function addToQueue($filename)
|
|
{
|
|
$files = glob(_MODULE_UPLOAD_PATH_ . $filename . '.{' . _IMPORT_FILE_EXTENSIONS_ . '}', GLOB_BRACE);
|
|
if (!count($files)) {
|
|
return false;
|
|
}
|
|
|
|
array_push($this->queue, $filename);
|
|
}
|
|
|
|
/**
|
|
* @param string $filename
|
|
*/
|
|
public function delFromQueue($filename)
|
|
{
|
|
$this->queue = array_diff($this->queue, array($filename));
|
|
}
|
|
}
|