mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-30 20:27:07 +09:00
* Replace usage of array_get * Fixes * And a few more * Remove remaining references * Update Service.php * Few more fixes * Fix.. I think? * Fix Client / Invoice updates * Fix stats * Fix issues noticed during code review * More fixes * And some more fixes :)
149 lines
4.1 KiB
PHP
149 lines
4.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* FOSSBilling.
|
|
*
|
|
* @copyright FOSSBilling (https://www.fossbilling.org)
|
|
* @license Apache-2.0
|
|
*
|
|
* Copyright FOSSBilling 2022
|
|
* This software may contain code previously used in the BoxBilling project.
|
|
* Copyright BoxBilling, Inc 2011-2021
|
|
*
|
|
* This source file is subject to the Apache-2.0 License that is bundled
|
|
* with this source code in the file LICENSE
|
|
*/
|
|
|
|
namespace Box\Mod\Queue;
|
|
|
|
class Service implements \Box\InjectionAwareInterface
|
|
{
|
|
protected $di;
|
|
|
|
/**
|
|
* @param mixed $di
|
|
*/
|
|
public function setDi($di)
|
|
{
|
|
$this->di = $di;
|
|
}
|
|
|
|
/**
|
|
* @return mixed
|
|
*/
|
|
public function getDi()
|
|
{
|
|
return $this->di;
|
|
}
|
|
|
|
public function uninstall()
|
|
{
|
|
$this->di['db']->exec('DROP TABLE queue;');
|
|
$this->di['db']->exec('DROP TABLE queue_message;');
|
|
}
|
|
|
|
public function install()
|
|
{
|
|
$sql = '
|
|
CREATE TABLE IF NOT EXISTS `queue` (
|
|
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
|
`name` varchar(100) DEFAULT NULL,
|
|
`module` varchar(255) DEFAULT NULL,
|
|
`timeout` bigint(20) DEFAULT NULL,
|
|
`iteration` int(10) DEFAULT NULL,
|
|
`created_at` varchar(35) DEFAULT NULL,
|
|
`updated_at` varchar(35) DEFAULT NULL,
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
|
|
';
|
|
$this->di['db']->exec($sql);
|
|
|
|
$sql = '
|
|
CREATE TABLE IF NOT EXISTS `queue_message` (
|
|
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
|
`queue_id` bigint(20) DEFAULT NULL,
|
|
`handle` char(32) DEFAULT NULL,
|
|
`handler` varchar(255) DEFAULT NULL,
|
|
`body` longblob,
|
|
`hash` char(32) DEFAULT NULL,
|
|
`timeout` double(18,2) DEFAULT NULL,
|
|
`log` text,
|
|
`execute_at` varchar(35) DEFAULT NULL,
|
|
`created_at` varchar(35) DEFAULT NULL,
|
|
`updated_at` varchar(35) DEFAULT NULL,
|
|
PRIMARY KEY (`id`),
|
|
KEY `queue_id_idx` (`queue_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
|
|
';
|
|
|
|
$this->di['db']->exec($sql);
|
|
$columns = $this->di['db']->getColumns('queue');
|
|
if (!array_key_exists('module', $columns)) {
|
|
$this->di['db']->exec('ALTER TABLE `queue` ADD `module` VARCHAR( 255 ) NULL AFTER `name`;');
|
|
}
|
|
|
|
if (!array_key_exists('iteration', $columns)) {
|
|
$this->di['db']->exec('ALTER TABLE `queue` ADD `iteration` VARCHAR( 255 ) NULL AFTER `timeout`;');
|
|
}
|
|
|
|
$columns = $this->di['db']->getColumns('queue_message');
|
|
if (!array_key_exists('handler', $columns)) {
|
|
$this->di['db']->exec('ALTER TABLE `queue_message` ADD `handler` VARCHAR( 255 ) NULL AFTER `handle`;');
|
|
}
|
|
|
|
if (!array_key_exists('execute_at', $columns)) {
|
|
$this->di['db']->exec('ALTER TABLE `queue_message` ADD `execute_at` VARCHAR( 255 ) NULL AFTER `log`;');
|
|
}
|
|
}
|
|
|
|
public function getSearchQuery($data)
|
|
{
|
|
$sql = 'SELECT *
|
|
FROM queue
|
|
WHERE 1 ';
|
|
|
|
$params = [];
|
|
|
|
$search = $data['search'] ?? null;
|
|
$name = $data['name'] ?? null;
|
|
$mod = $data['mod'] ?? null;
|
|
|
|
if ($mod) {
|
|
$sql .= ' AND mod = :mod ';
|
|
$params['mod'] = $mod;
|
|
}
|
|
|
|
if ($name) {
|
|
$sql .= ' AND name = :name ';
|
|
$params['name'] = $name;
|
|
}
|
|
|
|
if ($search) {
|
|
$sql .= ' AND (name LIKE :search)';
|
|
$params['search'] = '%' . $search . '%';
|
|
}
|
|
|
|
$sql .= ' ORDER BY id DESC';
|
|
|
|
return [$sql, $params];
|
|
}
|
|
|
|
public function toApiArray($row)
|
|
{
|
|
if ($row instanceof \RedBeanPHP\OODBBean) {
|
|
$row = $row->export();
|
|
}
|
|
|
|
$sql = 'SELECT COUNT(id) FROM queue_message WHERE queue_id = :id GROUP BY queue_id';
|
|
$count = $this->di['db']->getCell($sql, ['id' => $row['id']]);
|
|
$row['messages_count'] = ($count) ? $count : 0;
|
|
|
|
return $row;
|
|
}
|
|
|
|
public static function dummy($params)
|
|
{
|
|
throw new \Exception('Received params: ' . var_export($params, 1));
|
|
}
|
|
}
|