mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Change Indent space4 to tab
Signed-off-by: ytetsuro <phper.0o0@gmail.com>
This commit is contained in:
parent
e51cc2a85c
commit
c76e6901e7
@ -49,186 +49,186 @@ use Psr\Log\LoggerInterface;
|
||||
*/
|
||||
abstract class BaseCommand
|
||||
{
|
||||
/**
|
||||
* The group the command is lumped under
|
||||
* when listing commands.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $group;
|
||||
/**
|
||||
* The group the command is lumped under
|
||||
* when listing commands.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $group;
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* the Command's usage description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage;
|
||||
/**
|
||||
* the Command's usage description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage;
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description;
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description;
|
||||
|
||||
/**
|
||||
* the Command's options description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $options = array();
|
||||
/**
|
||||
* the Command's options description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $options = array();
|
||||
|
||||
/**
|
||||
* the Command's Arguments description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $arguments = array();
|
||||
/**
|
||||
* the Command's Arguments description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $arguments = array();
|
||||
|
||||
/**
|
||||
* @var \Psr\Log\LoggerInterface
|
||||
*/
|
||||
protected $logger;
|
||||
/**
|
||||
* @var \Psr\Log\LoggerInterface
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* Instance of the CommandRunner controller
|
||||
* so commands can call other commands.
|
||||
*
|
||||
* @var \CodeIgniter\CLI\CommandRunner
|
||||
*/
|
||||
protected $commands;
|
||||
/**
|
||||
* Instance of the CommandRunner controller
|
||||
* so commands can call other commands.
|
||||
*
|
||||
* @var \CodeIgniter\CLI\CommandRunner
|
||||
*/
|
||||
protected $commands;
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function __construct(LoggerInterface $logger, CommandRunner $commands)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
$this->commands = $commands;
|
||||
}
|
||||
public function __construct(LoggerInterface $logger, CommandRunner $commands)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
$this->commands = $commands;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
abstract public function run(array $params);
|
||||
abstract public function run(array $params);
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Can be used by a command to run other commands.
|
||||
*
|
||||
* @param string $command
|
||||
* @param array $params
|
||||
*/
|
||||
protected function call(string $command, array $params = [])
|
||||
{
|
||||
// The CommandRunner will grab the first element
|
||||
// for the command name.
|
||||
array_unshift($params, $command);
|
||||
/**
|
||||
* Can be used by a command to run other commands.
|
||||
*
|
||||
* @param string $command
|
||||
* @param array $params
|
||||
*/
|
||||
protected function call(string $command, array $params = [])
|
||||
{
|
||||
// The CommandRunner will grab the first element
|
||||
// for the command name.
|
||||
array_unshift($params, $command);
|
||||
|
||||
return $this->commands->index($params);
|
||||
}
|
||||
return $this->commands->index($params);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* A simple method to display an error with line/file,
|
||||
* in child commands.
|
||||
*
|
||||
* @param \Exception $e
|
||||
*/
|
||||
protected function showError(\Exception $e)
|
||||
{
|
||||
CLI::newLine();
|
||||
CLI::error($e->getMessage());
|
||||
CLI::write($e->getFile() . ' - ' . $e->getLine());
|
||||
CLI::newLine();
|
||||
}
|
||||
/**
|
||||
* A simple method to display an error with line/file,
|
||||
* in child commands.
|
||||
*
|
||||
* @param \Exception $e
|
||||
*/
|
||||
protected function showError(\Exception $e)
|
||||
{
|
||||
CLI::newLine();
|
||||
CLI::error($e->getMessage());
|
||||
CLI::write($e->getFile() . ' - ' . $e->getLine());
|
||||
CLI::newLine();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Makes it simple to access our protected properties.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get(string $key)
|
||||
{
|
||||
if (isset($this->$key)) {
|
||||
return $this->$key;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Makes it simple to access our protected properties.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get(string $key)
|
||||
{
|
||||
if (isset($this->$key)) {
|
||||
return $this->$key;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* show Help include (usage,arguments,description,options)
|
||||
*
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function showHelp()
|
||||
{
|
||||
// 4 spaces insted of tab
|
||||
$tab = " ";
|
||||
CLI::write(lang('CLI.helpDescription'), 'yellow');
|
||||
CLI::write($tab . $this->description);
|
||||
CLI::newLine();
|
||||
/**
|
||||
* show Help include (usage,arguments,description,options)
|
||||
*
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function showHelp()
|
||||
{
|
||||
// 4 spaces insted of tab
|
||||
$tab = " ";
|
||||
CLI::write(lang('CLI.helpDescription'), 'yellow');
|
||||
CLI::write($tab . $this->description);
|
||||
CLI::newLine();
|
||||
|
||||
CLI::write(lang('CLI.helpUsage'), 'yellow');
|
||||
$usage = empty($this->usage) ? $this->name . " [arguments]" : $this->usage;
|
||||
CLI::write($tab . $usage);
|
||||
CLI::newLine();
|
||||
CLI::write(lang('CLI.helpUsage'), 'yellow');
|
||||
$usage = empty($this->usage) ? $this->name . " [arguments]" : $this->usage;
|
||||
CLI::write($tab . $usage);
|
||||
CLI::newLine();
|
||||
|
||||
$pad = max($this->getPad($this->options, 6), $this->getPad($this->arguments, 6));
|
||||
$pad = max($this->getPad($this->options, 6), $this->getPad($this->arguments, 6));
|
||||
|
||||
if (!empty($this->arguments))
|
||||
{
|
||||
CLI::write(lang('CLI.helpArguments'), 'yellow');
|
||||
foreach ($this->arguments as $argument => $description)
|
||||
{
|
||||
CLI::write($tab . CLI::color(str_pad($argument, $pad), 'green') . $description, 'yellow');
|
||||
}
|
||||
CLI::newLine();
|
||||
}
|
||||
if (!empty($this->arguments))
|
||||
{
|
||||
CLI::write(lang('CLI.helpArguments'), 'yellow');
|
||||
foreach ($this->arguments as $argument => $description)
|
||||
{
|
||||
CLI::write($tab . CLI::color(str_pad($argument, $pad), 'green') . $description, 'yellow');
|
||||
}
|
||||
CLI::newLine();
|
||||
}
|
||||
|
||||
if (!empty($this->options))
|
||||
{
|
||||
CLI::write(lang('CLI.helpOptions'), 'yellow');
|
||||
foreach ($this->options as $option => $description)
|
||||
{
|
||||
CLI::write($tab . CLI::color(str_pad($option, $pad), 'green') . $description, 'yellow');
|
||||
}
|
||||
CLI::newLine();
|
||||
}
|
||||
}
|
||||
if (!empty($this->options))
|
||||
{
|
||||
CLI::write(lang('CLI.helpOptions'), 'yellow');
|
||||
foreach ($this->options as $option => $description)
|
||||
{
|
||||
CLI::write($tab . CLI::color(str_pad($option, $pad), 'green') . $description, 'yellow');
|
||||
}
|
||||
CLI::newLine();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get pad for $key => $value array output
|
||||
*
|
||||
* @param array $array
|
||||
* @param int $pad
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPad($array, string $pad)
|
||||
{
|
||||
$max = 0;
|
||||
foreach ($array as $key => $value) {
|
||||
$max = max($max, strlen($key));
|
||||
}
|
||||
return $max + $pad;
|
||||
}
|
||||
/**
|
||||
* Get pad for $key => $value array output
|
||||
*
|
||||
* @param array $array
|
||||
* @param int $pad
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPad($array, string $pad)
|
||||
{
|
||||
$max = 0;
|
||||
foreach ($array as $key => $value) {
|
||||
$max = max($max, strlen($key));
|
||||
}
|
||||
return $max + $pad;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
}
|
||||
//--------------------------------------------------------------------
|
||||
}
|
||||
|
@ -40,50 +40,50 @@ use CodeIgniter\CodeIgniter;
|
||||
|
||||
class Console
|
||||
{
|
||||
/**
|
||||
* Main CodeIgniter instance.
|
||||
* @var CodeIgniter
|
||||
*/
|
||||
protected $app;
|
||||
/**
|
||||
* Main CodeIgniter instance.
|
||||
* @var CodeIgniter
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function __construct(CodeIgniter $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
public function __construct(CodeIgniter $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Runs the current command discovered on the CLI.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$path = CLI::getURI() ?: 'list';
|
||||
/**
|
||||
* Runs the current command discovered on the CLI.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$path = CLI::getURI() ?: 'list';
|
||||
|
||||
// Set the path for the application to route to.
|
||||
$this->app->setPath("ci{$path}");
|
||||
// Set the path for the application to route to.
|
||||
$this->app->setPath("ci{$path}");
|
||||
|
||||
return $this->app->run();
|
||||
}
|
||||
return $this->app->run();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Displays basic information about the Console.
|
||||
*/
|
||||
public function showHeader()
|
||||
{
|
||||
CLI::newLine(1);
|
||||
/**
|
||||
* Displays basic information about the Console.
|
||||
*/
|
||||
public function showHeader()
|
||||
{
|
||||
CLI::newLine(1);
|
||||
|
||||
CLI::write(CLI::color('CodeIgniter CLI Tool', 'green')
|
||||
. ' - Version '. CodeIgniter::CI_VERSION
|
||||
. ' - Server-Time: '. date('Y-m-d H:i:sa'));
|
||||
CLI::write(CLI::color('CodeIgniter CLI Tool', 'green')
|
||||
. ' - Version '. CodeIgniter::CI_VERSION
|
||||
. ' - Server-Time: '. date('Y-m-d H:i:sa'));
|
||||
|
||||
CLI::newLine(1);
|
||||
}
|
||||
CLI::newLine(1);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
@ -41,259 +41,259 @@ use CodeIgniter\CriticalError;
|
||||
|
||||
class PredisHandler implements CacheInterface
|
||||
{
|
||||
/**
|
||||
* Prefixed to all cache names.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
/**
|
||||
* Prefixed to all cache names.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
|
||||
/**
|
||||
* Default config
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
protected $config = [
|
||||
'scheme' => 'tcp',
|
||||
'host' => '127.0.0.1',
|
||||
'password' => null,
|
||||
'port' => 6379,
|
||||
'timeout' => 0,
|
||||
];
|
||||
/**
|
||||
* Default config
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
protected $config = [
|
||||
'scheme' => 'tcp',
|
||||
'host' => '127.0.0.1',
|
||||
'password' => null,
|
||||
'port' => 6379,
|
||||
'timeout' => 0,
|
||||
];
|
||||
|
||||
/**
|
||||
* Predis connection
|
||||
*
|
||||
* @var Predis
|
||||
*/
|
||||
protected $redis;
|
||||
/**
|
||||
* Predis connection
|
||||
*
|
||||
* @var Predis
|
||||
*/
|
||||
protected $redis;
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function __construct($config)
|
||||
{
|
||||
$this->prefix = $config->prefix ?: '';
|
||||
public function __construct($config)
|
||||
{
|
||||
$this->prefix = $config->prefix ?: '';
|
||||
|
||||
if (isset($config->redis))
|
||||
{
|
||||
$this->config = array_merge($this->config, $config->redis);
|
||||
}
|
||||
}
|
||||
if (isset($config->redis))
|
||||
{
|
||||
$this->config = array_merge($this->config, $config->redis);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Takes care of any handler-specific setup that must be done.
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Create a new instance of Predis\Client
|
||||
$this->redis = new \Predis\Client($this->config, ['prefix' => $this->prefix]);
|
||||
/**
|
||||
* Takes care of any handler-specific setup that must be done.
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Create a new instance of Predis\Client
|
||||
$this->redis = new \Predis\Client($this->config, ['prefix' => $this->prefix]);
|
||||
|
||||
// Check if the connection is valid by trying to get the time.
|
||||
$this->redis->time();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
// thrown if can't connect to redis server.
|
||||
throw new CriticalError('Cache: Predis connection refused ('.$e->getMessage().')');
|
||||
}
|
||||
}
|
||||
// Check if the connection is valid by trying to get the time.
|
||||
$this->redis->time();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
// thrown if can't connect to redis server.
|
||||
throw new CriticalError('Cache: Predis connection refused ('.$e->getMessage().')');
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Attempts to fetch an item from the cache store.
|
||||
*
|
||||
* @param string $key Cache item name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get(string $key)
|
||||
{
|
||||
$data = array_combine(
|
||||
['__ci_type', '__ci_value'],
|
||||
$this->redis->hmget($key, ['__ci_type', '__ci_value'])
|
||||
);
|
||||
/**
|
||||
* Attempts to fetch an item from the cache store.
|
||||
*
|
||||
* @param string $key Cache item name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get(string $key)
|
||||
{
|
||||
$data = array_combine(
|
||||
['__ci_type', '__ci_value'],
|
||||
$this->redis->hmget($key, ['__ci_type', '__ci_value'])
|
||||
);
|
||||
|
||||
if (! isset($data['__ci_type'], $data['__ci_value']) OR $data['__ci_value'] === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (! isset($data['__ci_type'], $data['__ci_value']) OR $data['__ci_value'] === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ($data['__ci_type'])
|
||||
{
|
||||
case 'array':
|
||||
case 'object':
|
||||
return unserialize($data['__ci_value']);
|
||||
case 'boolean':
|
||||
case 'integer':
|
||||
case 'double': // Yes, 'double' is returned and NOT 'float'
|
||||
case 'string':
|
||||
case 'NULL':
|
||||
return settype($data['__ci_value'], $data['__ci_type'])
|
||||
? $data['__ci_value']
|
||||
: false;
|
||||
case 'resource':
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
switch ($data['__ci_type'])
|
||||
{
|
||||
case 'array':
|
||||
case 'object':
|
||||
return unserialize($data['__ci_value']);
|
||||
case 'boolean':
|
||||
case 'integer':
|
||||
case 'double': // Yes, 'double' is returned and NOT 'float'
|
||||
case 'string':
|
||||
case 'NULL':
|
||||
return settype($data['__ci_value'], $data['__ci_type'])
|
||||
? $data['__ci_value']
|
||||
: false;
|
||||
case 'resource':
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Saves an item to the cache store.
|
||||
*
|
||||
* The $raw parameter is only utilized by predis in order to
|
||||
* allow usage of increment() and decrement().
|
||||
*
|
||||
* @param string $key Cache item name
|
||||
* @param $value the data to save
|
||||
* @param null $ttl Time To Live, in seconds (default 60)
|
||||
* @param bool $raw Whether to store the raw value.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function save(string $key, $value, int $ttl = 60, bool $raw = false)
|
||||
{
|
||||
switch ($data_type = gettype($value))
|
||||
{
|
||||
case 'array':
|
||||
case 'object':
|
||||
$value = serialize($value);
|
||||
break;
|
||||
case 'boolean':
|
||||
case 'integer':
|
||||
case 'double': // Yes, 'double' is returned and NOT 'float'
|
||||
case 'string':
|
||||
case 'NULL':
|
||||
break;
|
||||
case 'resource':
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Saves an item to the cache store.
|
||||
*
|
||||
* The $raw parameter is only utilized by predis in order to
|
||||
* allow usage of increment() and decrement().
|
||||
*
|
||||
* @param string $key Cache item name
|
||||
* @param $value the data to save
|
||||
* @param null $ttl Time To Live, in seconds (default 60)
|
||||
* @param bool $raw Whether to store the raw value.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function save(string $key, $value, int $ttl = 60, bool $raw = false)
|
||||
{
|
||||
switch ($data_type = gettype($value))
|
||||
{
|
||||
case 'array':
|
||||
case 'object':
|
||||
$value = serialize($value);
|
||||
break;
|
||||
case 'boolean':
|
||||
case 'integer':
|
||||
case 'double': // Yes, 'double' is returned and NOT 'float'
|
||||
case 'string':
|
||||
case 'NULL':
|
||||
break;
|
||||
case 'resource':
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->redis->hmset($key, ['__ci_type' => $data_type, '__ci_value' => $value]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->redis->expireat($key, time()+$ttl);
|
||||
if (! $this->redis->hmset($key, ['__ci_type' => $data_type, '__ci_value' => $value]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
$this->redis->expireat($key, time()+$ttl);
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a specific item from the cache store.
|
||||
*
|
||||
* @param string $key Cache item name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function delete(string $key)
|
||||
{
|
||||
return ($this->redis->del($key) === 1);
|
||||
}
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
/**
|
||||
* Deletes a specific item from the cache store.
|
||||
*
|
||||
* @param string $key Cache item name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function delete(string $key)
|
||||
{
|
||||
return ($this->redis->del($key) === 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs atomic incrementation of a raw stored value.
|
||||
*
|
||||
* @param string $key Cache ID
|
||||
* @param int $offset Step/value to increase by
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function increment(string $key, int $offset = 1)
|
||||
{
|
||||
return $this->redis->hincrby($key, 'data', $offset);
|
||||
}
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
/**
|
||||
* Performs atomic incrementation of a raw stored value.
|
||||
*
|
||||
* @param string $key Cache ID
|
||||
* @param int $offset Step/value to increase by
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function increment(string $key, int $offset = 1)
|
||||
{
|
||||
return $this->redis->hincrby($key, 'data', $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs atomic decrementation of a raw stored value.
|
||||
*
|
||||
* @param string $key Cache ID
|
||||
* @param int $offset Step/value to increase by
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function decrement(string $key, int $offset = 1)
|
||||
{
|
||||
return $this->redis->hincrby($key, 'data', -$offset);
|
||||
}
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
/**
|
||||
* Performs atomic decrementation of a raw stored value.
|
||||
*
|
||||
* @param string $key Cache ID
|
||||
* @param int $offset Step/value to increase by
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function decrement(string $key, int $offset = 1)
|
||||
{
|
||||
return $this->redis->hincrby($key, 'data', -$offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will delete all items in the entire cache.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function clean()
|
||||
{
|
||||
return $this->redis->flushdb();
|
||||
}
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
/**
|
||||
* Will delete all items in the entire cache.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function clean()
|
||||
{
|
||||
return $this->redis->flushdb();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information on the entire cache.
|
||||
*
|
||||
* The information returned and the structure of the data
|
||||
* varies depending on the handler.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCacheInfo()
|
||||
{
|
||||
return $this->redis->info();
|
||||
}
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
/**
|
||||
* Returns information on the entire cache.
|
||||
*
|
||||
* The information returned and the structure of the data
|
||||
* varies depending on the handler.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCacheInfo()
|
||||
{
|
||||
return $this->redis->info();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns detailed information about the specific item in the cache.
|
||||
*
|
||||
* @param string $key Cache item name.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMetaData(string $key)
|
||||
{
|
||||
$data = array_combine(['__ci_value'], $this->redis->hmget($key, ['__ci_value']));
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
if (isset($data['__ci_value']) AND $data['__ci_value'] !== false)
|
||||
{
|
||||
return array(
|
||||
'expire' => time() + $this->redis->ttl($key),
|
||||
'data' => $data['__ci_value']
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Returns detailed information about the specific item in the cache.
|
||||
*
|
||||
* @param string $key Cache item name.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMetaData(string $key)
|
||||
{
|
||||
$data = array_combine(['__ci_value'], $this->redis->hmget($key, ['__ci_value']));
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
if (isset($data['__ci_value']) AND $data['__ci_value'] !== false)
|
||||
{
|
||||
return array(
|
||||
'expire' => time() + $this->redis->ttl($key),
|
||||
'data' => $data['__ci_value']
|
||||
);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the driver is supported on this system.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isSupported(): bool
|
||||
{
|
||||
return class_exists('\Predis\Client');
|
||||
}
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
/**
|
||||
* Determines if the driver is supported on this system.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isSupported(): bool
|
||||
{
|
||||
return class_exists('\Predis\Client');
|
||||
}
|
||||
|
||||
}
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -47,117 +47,117 @@ use Config\Autoload;
|
||||
*/
|
||||
class CreateMigration extends BaseCommand
|
||||
{
|
||||
protected $group = 'Database';
|
||||
protected $group = 'Database';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:create';
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:create';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Creates a new migration file.';
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Creates a new migration file.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'migrate:create [migration_name] [Options]';
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'migrate:create [migration_name] [Options]';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = array(
|
||||
'migration_name' => 'The migration file name'
|
||||
);
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = array(
|
||||
'migration_name' => 'The migration file name'
|
||||
);
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'-n' => 'Set migration namespace'
|
||||
);
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'-n' => 'Set migration namespace'
|
||||
);
|
||||
|
||||
/**
|
||||
* Creates a new migration file with the current timestamp.
|
||||
* @todo Have this check the settings and see what type of file it should create (timestamp or sequential)
|
||||
*/
|
||||
public function run(array $params=[])
|
||||
{
|
||||
/**
|
||||
* Creates a new migration file with the current timestamp.
|
||||
* @todo Have this check the settings and see what type of file it should create (timestamp or sequential)
|
||||
*/
|
||||
public function run(array $params=[])
|
||||
{
|
||||
|
||||
$name = array_shift($params);
|
||||
$name = array_shift($params);
|
||||
|
||||
if (empty($name))
|
||||
{
|
||||
$name = CLI::prompt(lang('Migrations.migNameMigration'));
|
||||
}
|
||||
if (empty($name))
|
||||
{
|
||||
$name = CLI::prompt(lang('Migrations.migNameMigration'));
|
||||
}
|
||||
|
||||
if (empty($name))
|
||||
{
|
||||
CLI::error(lang('Migrations.migBadCreateName'));
|
||||
return;
|
||||
}
|
||||
$namespace = CLI::getOption('n');
|
||||
$homepath = APPPATH;
|
||||
if (empty($name))
|
||||
{
|
||||
CLI::error(lang('Migrations.migBadCreateName'));
|
||||
return;
|
||||
}
|
||||
$namespace = CLI::getOption('n');
|
||||
$homepath = APPPATH;
|
||||
|
||||
if (!empty($ns))
|
||||
{
|
||||
// Get all namespaces form PSR4 paths.
|
||||
$config = new Autoload();
|
||||
$namespaces = $config->psr4;
|
||||
if (!empty($ns))
|
||||
{
|
||||
// Get all namespaces form PSR4 paths.
|
||||
$config = new Autoload();
|
||||
$namespaces = $config->psr4;
|
||||
|
||||
foreach ($namespaces as $namespace => $path) {
|
||||
foreach ($namespaces as $namespace => $path) {
|
||||
|
||||
if ($namespace == $ns ) {
|
||||
$homepath =realpath($path);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
$ns= "App";
|
||||
}
|
||||
if ($namespace == $ns ) {
|
||||
$homepath =realpath($path);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
$ns= "App";
|
||||
}
|
||||
|
||||
$path = $homepath.'/Database/Migrations/'.date('YmdHis_').$name.'.php';
|
||||
$path = $homepath.'/Database/Migrations/'.date('YmdHis_').$name.'.php';
|
||||
|
||||
$template =<<<EOD
|
||||
<?php namespace $ns\Database\Migrations;
|
||||
$template =<<<EOD
|
||||
<?php namespace $ns\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
class Migration_{name} extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
class Migration_{name} extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
EOD;
|
||||
$template = str_replace('{name}', $name, $template);
|
||||
$template = str_replace('{name}', $name, $template);
|
||||
|
||||
helper('filesystem');
|
||||
if (! write_file($path, $template))
|
||||
{
|
||||
CLI::error(lang('Migrations.migWriteError'));
|
||||
return;
|
||||
}
|
||||
helper('filesystem');
|
||||
if (! write_file($path, $template))
|
||||
{
|
||||
CLI::error(lang('Migrations.migWriteError'));
|
||||
return;
|
||||
}
|
||||
|
||||
CLI::write('Created file: '. CLI::color(str_replace($homepath, $ns, $path), 'green'));
|
||||
}
|
||||
CLI::write('Created file: '. CLI::color(str_replace($homepath, $ns, $path), 'green'));
|
||||
}
|
||||
}
|
||||
|
@ -47,69 +47,69 @@ use Config\Services;
|
||||
*/
|
||||
class MigrateCurrent extends BaseCommand
|
||||
{
|
||||
protected $group = 'Database';
|
||||
protected $group = 'Database';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:current';
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:current';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Migrates us up or down to the version specified as $currentVersion in the migrations config file.';
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Migrates us up or down to the version specified as $currentVersion in the migrations config file.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'migrate:current [options]';
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'migrate:current [options]';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'-g' => 'Set database group'
|
||||
);
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'-g' => 'Set database group'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Migrates us up or down to the version specified as $currentVersion
|
||||
* in the migrations config file.
|
||||
*/
|
||||
public function run(array $params=[])
|
||||
{
|
||||
$runner = Services::migrations();
|
||||
/**
|
||||
* Migrates us up or down to the version specified as $currentVersion
|
||||
* in the migrations config file.
|
||||
*/
|
||||
public function run(array $params=[])
|
||||
{
|
||||
$runner = Services::migrations();
|
||||
|
||||
CLI::write(lang('Migrations.migToVersion'), 'yellow');
|
||||
CLI::write(lang('Migrations.migToVersion'), 'yellow');
|
||||
|
||||
$group = CLI::getOption('g');
|
||||
try {
|
||||
$runner->current($group);
|
||||
$messages = $runner->getCliMessages();
|
||||
foreach ($messages as $message) {
|
||||
CLI::write($message);
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->showError($e);
|
||||
}
|
||||
$group = CLI::getOption('g');
|
||||
try {
|
||||
$runner->current($group);
|
||||
$messages = $runner->getCliMessages();
|
||||
foreach ($messages as $message) {
|
||||
CLI::write($message);
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->showError($e);
|
||||
}
|
||||
|
||||
CLI::write('Done');
|
||||
}
|
||||
CLI::write('Done');
|
||||
}
|
||||
}
|
||||
|
@ -47,77 +47,77 @@ use Config\Services;
|
||||
*/
|
||||
class MigrateLatest extends BaseCommand
|
||||
{
|
||||
protected $group = 'Database';
|
||||
protected $group = 'Database';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:latest';
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:latest';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Migrates the database to the latest schema.';
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Migrates the database to the latest schema.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'migrate:latest [options]';
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'migrate:latest [options]';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'-n' => 'Set migration namespace',
|
||||
'-g' => 'Set database group',
|
||||
'-all' => 'Set latest for all namespace, will ignore (-n) option'
|
||||
);
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'-n' => 'Set migration namespace',
|
||||
'-g' => 'Set database group',
|
||||
'-all' => 'Set latest for all namespace, will ignore (-n) option'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Ensures that all migrations have been run.
|
||||
*/
|
||||
public function run(array $params=[])
|
||||
{
|
||||
$runner = Services::migrations();
|
||||
/**
|
||||
* Ensures that all migrations have been run.
|
||||
*/
|
||||
public function run(array $params=[])
|
||||
{
|
||||
$runner = Services::migrations();
|
||||
|
||||
CLI::write(lang('Migrations.migToLatest'), 'yellow');
|
||||
CLI::write(lang('Migrations.migToLatest'), 'yellow');
|
||||
|
||||
$namespace = CLI::getOption('n');
|
||||
$group = CLI::getOption('g');
|
||||
|
||||
try {
|
||||
if (! is_null(CLI::getOption('all'))){
|
||||
$runner->latestAll($group);
|
||||
}else{
|
||||
$runner->latest($namespace,$group);
|
||||
}
|
||||
$messages = $runner->getCliMessages();
|
||||
foreach ($messages as $message) {
|
||||
CLI::write($message);
|
||||
}
|
||||
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->showError($e);
|
||||
}
|
||||
$namespace = CLI::getOption('n');
|
||||
$group = CLI::getOption('g');
|
||||
|
||||
CLI::write('Done');
|
||||
}
|
||||
try {
|
||||
if (! is_null(CLI::getOption('all'))){
|
||||
$runner->latestAll($group);
|
||||
}else{
|
||||
$runner->latest($namespace,$group);
|
||||
}
|
||||
$messages = $runner->getCliMessages();
|
||||
foreach ($messages as $message) {
|
||||
CLI::write($message);
|
||||
}
|
||||
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->showError($e);
|
||||
}
|
||||
|
||||
CLI::write('Done');
|
||||
}
|
||||
}
|
||||
|
@ -48,54 +48,54 @@ use Config\Services;
|
||||
*/
|
||||
class MigrateRefresh extends BaseCommand
|
||||
{
|
||||
protected $group = 'Database';
|
||||
protected $group = 'Database';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:refresh';
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:refresh';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Does a rollback followed by a latest to refresh the current state of the database.';
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Does a rollback followed by a latest to refresh the current state of the database.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'migrate:refresh [Options]';
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'migrate:refresh [Options]';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'-n' => 'Set migration namespace',
|
||||
'-g' => 'Set database group',
|
||||
'-all' => 'Set latest for all namespace, will ignore (-n) option'
|
||||
);
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'-n' => 'Set migration namespace',
|
||||
'-g' => 'Set database group',
|
||||
'-all' => 'Set latest for all namespace, will ignore (-n) option'
|
||||
);
|
||||
|
||||
/**
|
||||
* Does a rollback followed by a latest to refresh the current state
|
||||
* of the database.
|
||||
*/
|
||||
public function run(array $params=[])
|
||||
{
|
||||
$this->call('migrate:rollback');
|
||||
$this->call('migrate:latest');
|
||||
}
|
||||
/**
|
||||
* Does a rollback followed by a latest to refresh the current state
|
||||
* of the database.
|
||||
*/
|
||||
public function run(array $params=[])
|
||||
{
|
||||
$this->call('migrate:rollback');
|
||||
$this->call('migrate:latest');
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +1,40 @@
|
||||
<?php namespace CodeIgniter\Commands\Database;
|
||||
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2017, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author CodeIgniter Dev Team
|
||||
* @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2017, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author CodeIgniter Dev Team
|
||||
* @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
@ -42,94 +42,94 @@ use Config\Services;
|
||||
use Config\Autoload;
|
||||
|
||||
/**
|
||||
* Runs all of the migrations in reverse order, until they have
|
||||
* all been un-applied.
|
||||
*
|
||||
* @package CodeIgniter\Commands
|
||||
*/
|
||||
* Runs all of the migrations in reverse order, until they have
|
||||
* all been un-applied.
|
||||
*
|
||||
* @package CodeIgniter\Commands
|
||||
*/
|
||||
class MigrateRollback extends BaseCommand
|
||||
{
|
||||
protected $group = 'Database';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:rollback';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Runs all of the migrations in reverse order, until they have all been un-applied.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'migrate:rollback [Options]';
|
||||
protected $group = 'Database';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:rollback';
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'-n' => 'Set migration namespace',
|
||||
'-g' => 'Set database group',
|
||||
'-all' => 'Set latest for all namespace, will ignore (-n) option'
|
||||
);
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Runs all of the migrations in reverse order, until they have all been un-applied.';
|
||||
|
||||
/**
|
||||
* Runs all of the migrations in reverse order, until they have
|
||||
* all been un-applied.
|
||||
*/
|
||||
public function run(array $params=[])
|
||||
{
|
||||
$runner = Services::migrations();
|
||||
|
||||
CLI::write(lang('Migrations.migRollingBack'), 'yellow');
|
||||
$group = CLI::getOption('g');
|
||||
if(!is_null($group)){
|
||||
$runner->setGroup($group);
|
||||
}
|
||||
try {
|
||||
if (is_null(CLI::getOption('all'))){
|
||||
$namespace =CLI::getOption('n');
|
||||
$runner->version(0,$namespace);
|
||||
}else{
|
||||
// Get all namespaces form PSR4 paths.
|
||||
$config = new Autoload();
|
||||
$namespaces = $config->psr4;
|
||||
foreach ($namespaces as $namespace => $path) {
|
||||
$runner->setNamespace($namespace);
|
||||
$migrations = $runner->findMigrations();
|
||||
if (empty($migrations)) {
|
||||
continue;
|
||||
}
|
||||
$runner->version(0,$namespace,$group);
|
||||
}
|
||||
}
|
||||
$messages = $runner->getCliMessages();
|
||||
foreach ($messages as $message) {
|
||||
CLI::write($message);
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->showError($e);
|
||||
}
|
||||
|
||||
CLI::write('Done');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'migrate:rollback [Options]';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'-n' => 'Set migration namespace',
|
||||
'-g' => 'Set database group',
|
||||
'-all' => 'Set latest for all namespace, will ignore (-n) option'
|
||||
);
|
||||
|
||||
/**
|
||||
* Runs all of the migrations in reverse order, until they have
|
||||
* all been un-applied.
|
||||
*/
|
||||
public function run(array $params=[])
|
||||
{
|
||||
$runner = Services::migrations();
|
||||
|
||||
CLI::write(lang('Migrations.migRollingBack'), 'yellow');
|
||||
$group = CLI::getOption('g');
|
||||
if(!is_null($group)){
|
||||
$runner->setGroup($group);
|
||||
}
|
||||
try {
|
||||
if (is_null(CLI::getOption('all'))){
|
||||
$namespace =CLI::getOption('n');
|
||||
$runner->version(0,$namespace);
|
||||
}else{
|
||||
// Get all namespaces form PSR4 paths.
|
||||
$config = new Autoload();
|
||||
$namespaces = $config->psr4;
|
||||
foreach ($namespaces as $namespace => $path) {
|
||||
$runner->setNamespace($namespace);
|
||||
$migrations = $runner->findMigrations();
|
||||
if (empty($migrations)) {
|
||||
continue;
|
||||
}
|
||||
$runner->version(0,$namespace,$group);
|
||||
}
|
||||
}
|
||||
$messages = $runner->getCliMessages();
|
||||
foreach ($messages as $message) {
|
||||
CLI::write($message);
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->showError($e);
|
||||
}
|
||||
|
||||
CLI::write('Done');
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +1,40 @@
|
||||
<?php namespace CodeIgniter\Commands\Database;
|
||||
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2017, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author CodeIgniter Dev Team
|
||||
* @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2017, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author CodeIgniter Dev Team
|
||||
* @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
@ -42,110 +42,110 @@ use Config\Services;
|
||||
use Config\Autoload;
|
||||
|
||||
/**
|
||||
* Displays a list of all migrations and whether they've been run or not.
|
||||
*
|
||||
* @package CodeIgniter\Commands
|
||||
*/
|
||||
* Displays a list of all migrations and whether they've been run or not.
|
||||
*
|
||||
* @package CodeIgniter\Commands
|
||||
*/
|
||||
class MigrateStatus extends BaseCommand
|
||||
{
|
||||
protected $group = 'Database';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:status';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Displays a list of all migrations and whether they\'ve been run or not.';
|
||||
protected $group = 'Database';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'migrate:status [Options]';
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:status';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Displays a list of all migrations and whether they\'ve been run or not.';
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'-g' => 'Set database group'
|
||||
);
|
||||
|
||||
/**
|
||||
* Displays a list of all migrations and whether they've been run or not.
|
||||
*/
|
||||
public function run(array $params=[])
|
||||
{
|
||||
$runner = Services::migrations();
|
||||
|
||||
if(! is_null(CLI::getOption('g'))){
|
||||
$runner->setGroup(CLI::getOption('g'));
|
||||
}
|
||||
|
||||
// Get all namespaces form PSR4 paths.
|
||||
$config = new Autoload();
|
||||
$namespaces = $config->psr4;
|
||||
|
||||
// Loop for all $namespaces
|
||||
foreach ($namespaces as $namespace => $path) {
|
||||
|
||||
$runner->setNamespace($namespace);
|
||||
$migrations = $runner->findMigrations();
|
||||
$history = $runner->getHistory();
|
||||
|
||||
if (empty($migrations))
|
||||
{
|
||||
CLI::error("$namespace: " .lang('Migrations.migNoneFound'));
|
||||
continue;
|
||||
}
|
||||
|
||||
ksort($migrations);
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'migrate:status [Options]';
|
||||
|
||||
CLI::newLine(1);
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
CLI::write(lang('Migrations.migHistoryFor') . "$namespace: " , 'green');
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'-g' => 'Set database group'
|
||||
);
|
||||
|
||||
CLI::newLine(1);
|
||||
/**
|
||||
* Displays a list of all migrations and whether they've been run or not.
|
||||
*/
|
||||
public function run(array $params=[])
|
||||
{
|
||||
$runner = Services::migrations();
|
||||
|
||||
$max = 0;
|
||||
foreach ($migrations as $version => $migration)
|
||||
{
|
||||
$file = substr($migration->name, strpos($migration->name, $version.'_'));
|
||||
$migrations[$version]->name = $file;
|
||||
|
||||
$max = max($max, strlen($file));
|
||||
}
|
||||
|
||||
CLI::write(str_pad(lang('Migrations.filename'), $max+6).lang('Migrations.migOn'),'yellow');
|
||||
|
||||
|
||||
foreach ($migrations as $version => $migration)
|
||||
{
|
||||
$date = '';
|
||||
foreach ($history as $row)
|
||||
{
|
||||
if ($row['version'] != $version) continue;
|
||||
|
||||
$date = date ("Y-m-d H:i:s", $row['time']);
|
||||
}
|
||||
CLI::write(str_pad($migration->name, $max+6). ($date ? $date : '---'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(! is_null(CLI::getOption('g'))){
|
||||
$runner->setGroup(CLI::getOption('g'));
|
||||
}
|
||||
|
||||
// Get all namespaces form PSR4 paths.
|
||||
$config = new Autoload();
|
||||
$namespaces = $config->psr4;
|
||||
|
||||
// Loop for all $namespaces
|
||||
foreach ($namespaces as $namespace => $path) {
|
||||
|
||||
$runner->setNamespace($namespace);
|
||||
$migrations = $runner->findMigrations();
|
||||
$history = $runner->getHistory();
|
||||
|
||||
if (empty($migrations))
|
||||
{
|
||||
CLI::error("$namespace: " .lang('Migrations.migNoneFound'));
|
||||
continue;
|
||||
}
|
||||
|
||||
ksort($migrations);
|
||||
|
||||
CLI::newLine(1);
|
||||
|
||||
CLI::write(lang('Migrations.migHistoryFor') . "$namespace: " , 'green');
|
||||
|
||||
CLI::newLine(1);
|
||||
|
||||
$max = 0;
|
||||
foreach ($migrations as $version => $migration)
|
||||
{
|
||||
$file = substr($migration->name, strpos($migration->name, $version.'_'));
|
||||
$migrations[$version]->name = $file;
|
||||
|
||||
$max = max($max, strlen($file));
|
||||
}
|
||||
|
||||
CLI::write(str_pad(lang('Migrations.filename'), $max+6).lang('Migrations.migOn'),'yellow');
|
||||
|
||||
|
||||
foreach ($migrations as $version => $migration)
|
||||
{
|
||||
$date = '';
|
||||
foreach ($history as $row)
|
||||
{
|
||||
if ($row['version'] != $version) continue;
|
||||
|
||||
$date = date ("Y-m-d H:i:s", $row['time']);
|
||||
}
|
||||
CLI::write(str_pad($migration->name, $max+6). ($date ? $date : '---'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,85 +47,85 @@ use Config\Services;
|
||||
*/
|
||||
class MigrateVersion extends BaseCommand
|
||||
{
|
||||
protected $group = 'Database';
|
||||
protected $group = 'Database';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:version';
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:version';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Migrates the database up or down to get to the specified version.';
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Migrates the database up or down to get to the specified version.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'migrate:version [version_number] [Options]';
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'migrate:version [version_number] [Options]';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = array(
|
||||
'version_number' => 'The version number to migrate'
|
||||
);
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = array(
|
||||
'version_number' => 'The version number to migrate'
|
||||
);
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'-n' => 'Set migration namespace',
|
||||
'-g' => 'Set database group'
|
||||
);
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'-n' => 'Set migration namespace',
|
||||
'-g' => 'Set database group'
|
||||
);
|
||||
|
||||
/**
|
||||
* Migrates the database up or down to get to the specified version.
|
||||
*/
|
||||
public function run(array $params=[])
|
||||
{
|
||||
$runner = Services::migrations();
|
||||
/**
|
||||
* Migrates the database up or down to get to the specified version.
|
||||
*/
|
||||
public function run(array $params=[])
|
||||
{
|
||||
$runner = Services::migrations();
|
||||
|
||||
// Get the version number
|
||||
$version = array_shift($params);
|
||||
// Get the version number
|
||||
$version = array_shift($params);
|
||||
|
||||
if (is_null($version))
|
||||
{
|
||||
$version = CLI::prompt(lang('Migrations.version'));
|
||||
}
|
||||
if (is_null($version))
|
||||
{
|
||||
$version = CLI::prompt(lang('Migrations.version'));
|
||||
}
|
||||
|
||||
if (is_null($version))
|
||||
{
|
||||
CLI::error(lang('Migrations.invalidVersion'));
|
||||
exit();
|
||||
}
|
||||
if (is_null($version))
|
||||
{
|
||||
CLI::error(lang('Migrations.invalidVersion'));
|
||||
exit();
|
||||
}
|
||||
|
||||
CLI::write(sprintf(lang('Migrations.migToVersionPH'), $version), 'yellow');
|
||||
|
||||
$namespace = CLI::getOption('n');
|
||||
$group = CLI::getOption('g');
|
||||
try {
|
||||
$runner->version($version, $namespace, $group);
|
||||
$messages = $runner->getCliMessages();
|
||||
foreach ($messages as $message) {
|
||||
CLI::write($message);
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->showError($e);
|
||||
}
|
||||
CLI::write(sprintf(lang('Migrations.migToVersionPH'), $version), 'yellow');
|
||||
|
||||
CLI::write('Done');
|
||||
}
|
||||
$namespace = CLI::getOption('n');
|
||||
$group = CLI::getOption('g');
|
||||
try {
|
||||
$runner->version($version, $namespace, $group);
|
||||
$messages = $runner->getCliMessages();
|
||||
foreach ($messages as $message) {
|
||||
CLI::write($message);
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->showError($e);
|
||||
}
|
||||
|
||||
CLI::write('Done');
|
||||
}
|
||||
}
|
||||
|
@ -49,73 +49,73 @@ use Config\Services;
|
||||
*/
|
||||
class Seed extends BaseCommand
|
||||
{
|
||||
protected $group = 'Database';
|
||||
protected $group = 'Database';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'db:seed';
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'db:seed';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Runs the specified seeder to populate known data into the database.';
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Runs the specified seeder to populate known data into the database.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'db:seed [seeder_name]';
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'db:seed [seeder_name]';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = array(
|
||||
'seeder_name' => 'The seeder name to run'
|
||||
);
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = array(
|
||||
'seeder_name' => 'The seeder name to run'
|
||||
);
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [];
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [];
|
||||
|
||||
/**
|
||||
* Runs all of the migrations in reverse order, until they have
|
||||
* all been un-applied.
|
||||
*/
|
||||
public function run(array $params=[])
|
||||
{
|
||||
$seeder = new Seeder(new \Config\Database());
|
||||
/**
|
||||
* Runs all of the migrations in reverse order, until they have
|
||||
* all been un-applied.
|
||||
*/
|
||||
public function run(array $params=[])
|
||||
{
|
||||
$seeder = new Seeder(new \Config\Database());
|
||||
|
||||
$seedName = array_shift($params);
|
||||
$seedName = array_shift($params);
|
||||
|
||||
if (empty($seedName))
|
||||
{
|
||||
$seedName = CLI::prompt(lang('Migrations.migSeeder'), 'DatabaseSeeder');
|
||||
}
|
||||
if (empty($seedName))
|
||||
{
|
||||
$seedName = CLI::prompt(lang('Migrations.migSeeder'), 'DatabaseSeeder');
|
||||
}
|
||||
|
||||
if (empty($seedName))
|
||||
{
|
||||
CLI::error(lang('Migrations.migMissingSeeder'));
|
||||
return;
|
||||
}
|
||||
if (empty($seedName))
|
||||
{
|
||||
CLI::error(lang('Migrations.migMissingSeeder'));
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$seeder->call($seedName);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->showError($e);
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
$seeder->call($seedName);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->showError($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,63 +49,63 @@ use CodeIgniter\CLI\CLI;
|
||||
*/
|
||||
class Help extends BaseCommand
|
||||
{
|
||||
protected $group = 'CodeIgniter';
|
||||
protected $group = 'CodeIgniter';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'help';
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'help';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Displays basic usage information.';
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Displays basic usage information.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'help command_name';
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'help command_name';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = array(
|
||||
'command_name' => 'The command name [default: "help"]'
|
||||
);
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = array(
|
||||
'command_name' => 'The command name [default: "help"]'
|
||||
);
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Displays the help for the ci.php cli script itself.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function run(array $params)
|
||||
{
|
||||
$command = array_shift($params);
|
||||
if(is_null($command)){
|
||||
$command = 'help';
|
||||
}
|
||||
/**
|
||||
* Displays the help for the ci.php cli script itself.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function run(array $params)
|
||||
{
|
||||
$command = array_shift($params);
|
||||
if(is_null($command)){
|
||||
$command = 'help';
|
||||
}
|
||||
|
||||
$commands = $this->commands->getCommands();
|
||||
$class=new $commands[$command]['class']($this->logger, $this->commands);
|
||||
$commands = $this->commands->getCommands();
|
||||
$class=new $commands[$command]['class']($this->logger, $this->commands);
|
||||
|
||||
$class->showHelp();
|
||||
}
|
||||
$class->showHelp();
|
||||
}
|
||||
}
|
||||
|
@ -49,148 +49,148 @@ use CodeIgniter\CLI\CLI;
|
||||
*/
|
||||
class ListCommands extends BaseCommand
|
||||
{
|
||||
protected $group = 'CodeIgniter';
|
||||
protected $group = 'CodeIgniter';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'list';
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'list';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Lists the available commands.';
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Lists the available commands.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'list';
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'list';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = array();
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = array();
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
|
||||
/**
|
||||
* The length of the longest command name.
|
||||
* Used during display in columns.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $maxFirstLength = 0;
|
||||
/**
|
||||
* The length of the longest command name.
|
||||
* Used during display in columns.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $maxFirstLength = 0;
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Displays the help for the ci.php cli script itself.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function run(array $params)
|
||||
{
|
||||
$commands = $this->commands->getCommands();
|
||||
/**
|
||||
* Displays the help for the ci.php cli script itself.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function run(array $params)
|
||||
{
|
||||
$commands = $this->commands->getCommands();
|
||||
|
||||
$this->describeCommands($commands);
|
||||
$this->describeCommands($commands);
|
||||
|
||||
CLI::newLine();
|
||||
}
|
||||
CLI::newLine();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Displays the commands on the CLI.
|
||||
*
|
||||
* @param array $commands
|
||||
*/
|
||||
protected function describeCommands(array $commands = [])
|
||||
{
|
||||
arsort($commands);
|
||||
/**
|
||||
* Displays the commands on the CLI.
|
||||
*
|
||||
* @param array $commands
|
||||
*/
|
||||
protected function describeCommands(array $commands = [])
|
||||
{
|
||||
arsort($commands);
|
||||
|
||||
$names = array_keys($commands);
|
||||
$descs = array_column($commands, 'description');
|
||||
$groups = array_column($commands, 'group');
|
||||
$lastGroup = '';
|
||||
$names = array_keys($commands);
|
||||
$descs = array_column($commands, 'description');
|
||||
$groups = array_column($commands, 'group');
|
||||
$lastGroup = '';
|
||||
|
||||
// Pad each item to the same length
|
||||
$names = $this->padArray($names, 2, 2);
|
||||
// Pad each item to the same length
|
||||
$names = $this->padArray($names, 2, 2);
|
||||
|
||||
for ($i = 0; $i < count($names); $i++)
|
||||
{
|
||||
$lastGroup = $this->describeGroup($groups[$i], $lastGroup);
|
||||
for ($i = 0; $i < count($names); $i++)
|
||||
{
|
||||
$lastGroup = $this->describeGroup($groups[$i], $lastGroup);
|
||||
|
||||
$out = CLI::color($names[$i], 'yellow');
|
||||
$out = CLI::color($names[$i], 'yellow');
|
||||
|
||||
if (isset($descs[$i]))
|
||||
{
|
||||
$out .= CLI::wrap($descs[$i], 125, strlen($names[$i]));
|
||||
}
|
||||
if (isset($descs[$i]))
|
||||
{
|
||||
$out .= CLI::wrap($descs[$i], 125, strlen($names[$i]));
|
||||
}
|
||||
|
||||
CLI::write($out);
|
||||
}
|
||||
}
|
||||
CLI::write($out);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Outputs the description, if necessary.
|
||||
*
|
||||
* @param string $new
|
||||
* @param string $old
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function describeGroup(string $new, string $old)
|
||||
{
|
||||
if ($new == $old)
|
||||
{
|
||||
return $old;
|
||||
}
|
||||
/**
|
||||
* Outputs the description, if necessary.
|
||||
*
|
||||
* @param string $new
|
||||
* @param string $old
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function describeGroup(string $new, string $old)
|
||||
{
|
||||
if ($new == $old)
|
||||
{
|
||||
return $old;
|
||||
}
|
||||
|
||||
CLI::newLine();
|
||||
CLI::write($new);
|
||||
CLI::newLine();
|
||||
CLI::write($new);
|
||||
|
||||
return $new;
|
||||
}
|
||||
return $new;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns a new array where all of the string elements have
|
||||
* been padding with trailing spaces to be the same length.
|
||||
*
|
||||
* @param array $array
|
||||
* @param int $extra // How many extra spaces to add at the end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function padArray($array, $extra = 2, $indent=0)
|
||||
{
|
||||
$max = max(array_map('strlen', $array))+$extra+$indent;
|
||||
/**
|
||||
* Returns a new array where all of the string elements have
|
||||
* been padding with trailing spaces to be the same length.
|
||||
*
|
||||
* @param array $array
|
||||
* @param int $extra // How many extra spaces to add at the end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function padArray($array, $extra = 2, $indent=0)
|
||||
{
|
||||
$max = max(array_map('strlen', $array))+$extra+$indent;
|
||||
|
||||
foreach ($array as &$item)
|
||||
{
|
||||
$item = str_repeat(' ', $indent).$item;
|
||||
$item = str_pad($item, $max);
|
||||
}
|
||||
foreach ($array as &$item)
|
||||
{
|
||||
$item = str_repeat(' ', $indent).$item;
|
||||
$item = str_pad($item, $max);
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
@ -42,70 +42,70 @@ use Config\App;
|
||||
|
||||
class CreateMigration extends BaseCommand
|
||||
{
|
||||
protected $group = 'CodeIgniter';
|
||||
protected $group = 'CodeIgniter';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'session:migration';
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'session:migration';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generates the migration file for database sessions.';
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generates the migration file for database sessions.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'session:migration';
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'session:migration';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = array();
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = array();
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
|
||||
/**
|
||||
* Creates a new migration file with the current timestamp.
|
||||
*/
|
||||
public function run(array $params=[])
|
||||
{
|
||||
$name = 'create_sessions_table';
|
||||
/**
|
||||
* Creates a new migration file with the current timestamp.
|
||||
*/
|
||||
public function run(array $params=[])
|
||||
{
|
||||
$name = 'create_sessions_table';
|
||||
|
||||
$path = APPPATH.'Database/Migrations/'.date('YmdHis_').$name.'.php';
|
||||
$path = APPPATH.'Database/Migrations/'.date('YmdHis_').$name.'.php';
|
||||
|
||||
$config = new App();
|
||||
$config = new App();
|
||||
|
||||
$data = [
|
||||
'matchIP' => $config->sessionMatchIP ?? false,
|
||||
'tableName' => $config->sessionSavePath ?? 'ci_sessions',
|
||||
];
|
||||
$data = [
|
||||
'matchIP' => $config->sessionMatchIP ?? false,
|
||||
'tableName' => $config->sessionSavePath ?? 'ci_sessions',
|
||||
];
|
||||
|
||||
$template = view('\CodeIgniter\Commands\Sessions\Views\migration.tpl', $data);
|
||||
$template = str_replace('@php', '<?php', $template);
|
||||
$template = view('\CodeIgniter\Commands\Sessions\Views\migration.tpl', $data);
|
||||
$template = str_replace('@php', '<?php', $template);
|
||||
|
||||
// Write the file out.
|
||||
helper('filesystem');
|
||||
if (! write_file($path, $template))
|
||||
{
|
||||
CLI::error(lang('Migrations.migWriteError'));
|
||||
return;
|
||||
}
|
||||
// Write the file out.
|
||||
helper('filesystem');
|
||||
if (! write_file($path, $template))
|
||||
{
|
||||
CLI::error(lang('Migrations.migWriteError'));
|
||||
return;
|
||||
}
|
||||
|
||||
CLI::write('Created file: '. CLI::color(str_replace(APPPATH, 'APPPATH/', $path), 'green'));
|
||||
}
|
||||
CLI::write('Created file: '. CLI::color(str_replace(APPPATH, 'APPPATH/', $path), 'green'));
|
||||
}
|
||||
}
|
||||
|
@ -40,28 +40,28 @@ use CodeIgniter\Database\Migration;
|
||||
|
||||
class Migration_create_sessions_table extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'INT', 'constraint' => 9, 'unsigned' => true, 'auto_increment' => true],
|
||||
'ip_address' => ['type' => 'VARCHAR', 'constraint' => 45, 'null' => false],
|
||||
'timestamp' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => false, 'default' => 0],
|
||||
'data' => ['type' => 'text', 'null' => false, 'default' => ''],
|
||||
]);
|
||||
public function up()
|
||||
{
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'INT', 'constraint' => 9, 'unsigned' => true, 'auto_increment' => true],
|
||||
'ip_address' => ['type' => 'VARCHAR', 'constraint' => 45, 'null' => false],
|
||||
'timestamp' => ['type' => 'INT', 'constraint' => 10, 'unsigned' => true, 'null' => false, 'default' => 0],
|
||||
'data' => ['type' => 'text', 'null' => false, 'default' => ''],
|
||||
]);
|
||||
|
||||
<?php if ($matchIP === true) : ?>
|
||||
$this->forge->addKey(['id', 'ip_address'], true);
|
||||
<?php else: ?>
|
||||
$this->forge->addKey('id', true);
|
||||
<?php endif ?>
|
||||
$this->forge->addKey('timestamp');
|
||||
$this->forge->createTable('<?= $tableName ?>', true);
|
||||
}
|
||||
<?php if ($matchIP === true) : ?>
|
||||
$this->forge->addKey(['id', 'ip_address'], true);
|
||||
<?php else: ?>
|
||||
$this->forge->addKey('id', true);
|
||||
<?php endif ?>
|
||||
$this->forge->addKey('timestamp');
|
||||
$this->forge->createTable('<?= $tableName ?>', true);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function down()
|
||||
{
|
||||
$this->forge->dropTable('<?= $tableName ?>', true);
|
||||
}
|
||||
public function down()
|
||||
{
|
||||
$this->forge->dropTable('<?= $tableName ?>', true);
|
||||
}
|
||||
}
|
||||
|
1174
system/Common.php
1174
system/Common.php
File diff suppressed because it is too large
Load Diff
@ -185,20 +185,20 @@ class DotEnv
|
||||
// value starts with a quote
|
||||
$quote = $value[0];
|
||||
$regexPattern = sprintf(
|
||||
'/^
|
||||
%1$s # match a quote at the start of the value
|
||||
( # capturing sub-pattern used
|
||||
(?: # we do not need to capture this
|
||||
[^%1$s\\\\] # any character other than a quote or backslash
|
||||
|\\\\\\\\ # or two backslashes together
|
||||
|\\\\%1$s # or an escaped quote e.g \"
|
||||
)* # as many characters that match the previous rules
|
||||
) # end of the capturing sub-pattern
|
||||
%1$s # and the closing quote
|
||||
.*$ # and discard any string after the closing quote
|
||||
/mx',
|
||||
$quote
|
||||
);
|
||||
'/^
|
||||
%1$s # match a quote at the start of the value
|
||||
( # capturing sub-pattern used
|
||||
(?: # we do not need to capture this
|
||||
[^%1$s\\\\] # any character other than a quote or backslash
|
||||
|\\\\\\\\ # or two backslashes together
|
||||
|\\\\%1$s # or an escaped quote e.g \"
|
||||
)* # as many characters that match the previous rules
|
||||
) # end of the capturing sub-pattern
|
||||
%1$s # and the closing quote
|
||||
.*$ # and discard any string after the closing quote
|
||||
/mx',
|
||||
$quote
|
||||
);
|
||||
$value = preg_replace($regexPattern, '$1', $value);
|
||||
$value = str_replace("\\$quote", $quote, $value);
|
||||
$value = str_replace('\\\\', '\\', $value);
|
||||
@ -241,22 +241,22 @@ class DotEnv
|
||||
$loader = $this;
|
||||
|
||||
$value = preg_replace_callback(
|
||||
'/\${([a-zA-Z0-9_]+)}/',
|
||||
function ($matchedPatterns) use ($loader)
|
||||
{
|
||||
'/\${([a-zA-Z0-9_]+)}/',
|
||||
function ($matchedPatterns) use ($loader)
|
||||
{
|
||||
$nestedVariable = $loader->getVariable($matchedPatterns[1]);
|
||||
|
||||
if (is_null($nestedVariable))
|
||||
{
|
||||
return $matchedPatterns[0];
|
||||
return $matchedPatterns[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
return $nestedVariable;
|
||||
return $nestedVariable;
|
||||
}
|
||||
},
|
||||
$value
|
||||
);
|
||||
},
|
||||
$value
|
||||
);
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
@ -87,13 +87,13 @@ class Controller
|
||||
*/
|
||||
protected $forceHTTPS = 0;
|
||||
|
||||
/**
|
||||
* Once validation has been run,
|
||||
* will hold the Validation instance.
|
||||
*
|
||||
* @var Validation
|
||||
*/
|
||||
protected $validator;
|
||||
/**
|
||||
* Once validation has been run,
|
||||
* will hold the Validation instance.
|
||||
*
|
||||
* @var Validation
|
||||
*/
|
||||
protected $validator;
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
@ -106,7 +106,7 @@ class Controller
|
||||
*/
|
||||
public function __construct(RequestInterface $request, ResponseInterface $response, Logger $logger = null)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->request = $request;
|
||||
|
||||
$this->response = $response;
|
||||
|
||||
@ -136,7 +136,7 @@ class Controller
|
||||
*/
|
||||
public function forceHTTPS(int $duration = 31536000)
|
||||
{
|
||||
force_https($duration, $this->request, $this->response);
|
||||
force_https($duration, $this->request, $this->response);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -159,7 +159,7 @@ class Controller
|
||||
*/
|
||||
protected function loadHelpers()
|
||||
{
|
||||
if (empty($this->helpers)) return;
|
||||
if (empty($this->helpers)) return;
|
||||
|
||||
foreach ($this->helpers as $helper)
|
||||
{
|
||||
@ -169,28 +169,28 @@ class Controller
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* A shortcut to performing validation on $_POST input. If validation
|
||||
* is not successful, a $errors property will be set on this class.
|
||||
*
|
||||
* @param \CodeIgniter\HTTP\RequestInterface $request
|
||||
* @param $rules
|
||||
* @param array|null $messages
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validate(RequestInterface $request, $rules, array $messages = null): bool
|
||||
{
|
||||
$this->validator = Services::validation();
|
||||
/**
|
||||
* A shortcut to performing validation on $_POST input. If validation
|
||||
* is not successful, a $errors property will be set on this class.
|
||||
*
|
||||
* @param \CodeIgniter\HTTP\RequestInterface $request
|
||||
* @param $rules
|
||||
* @param array|null $messages
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validate(RequestInterface $request, $rules, array $messages = null): bool
|
||||
{
|
||||
$this->validator = Services::validation();
|
||||
|
||||
$success = $this->validator->withRequest($request)
|
||||
->setRules($rules, $messages)
|
||||
->run();
|
||||
$success = $this->validator->withRequest($request)
|
||||
->setRules($rules, $messages)
|
||||
->run();
|
||||
|
||||
return $success;
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
}
|
||||
|
@ -279,44 +279,44 @@ abstract class BaseConnection implements ConnectionInterface
|
||||
*/
|
||||
protected $pretend = false;
|
||||
|
||||
/**
|
||||
* Transaction enabled flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $trans_enabled = true;
|
||||
/**
|
||||
* Transaction enabled flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $trans_enabled = true;
|
||||
|
||||
/**
|
||||
* Strict transaction mode flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $trans_strict = true;
|
||||
/**
|
||||
* Strict transaction mode flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $trans_strict = true;
|
||||
|
||||
/**
|
||||
* Transaction depth level
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_trans_depth = 0;
|
||||
/**
|
||||
* Transaction depth level
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_trans_depth = 0;
|
||||
|
||||
/**
|
||||
* Transaction status flag
|
||||
*
|
||||
* Used with transactions to determine if a rollback should occur.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_trans_status = true;
|
||||
/**
|
||||
* Transaction status flag
|
||||
*
|
||||
* Used with transactions to determine if a rollback should occur.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_trans_status = true;
|
||||
|
||||
/**
|
||||
* Transaction failure flag
|
||||
*
|
||||
* Used with transactions to determine if a transaction has failed.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_trans_failure = false;
|
||||
/**
|
||||
* Transaction failure flag
|
||||
*
|
||||
* Used with transactions to determine if a transaction has failed.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_trans_failure = false;
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
@ -327,21 +327,21 @@ abstract class BaseConnection implements ConnectionInterface
|
||||
*/
|
||||
public function __construct(array $params)
|
||||
{
|
||||
foreach ($params as $key => $value)
|
||||
{
|
||||
$this->$key = $value;
|
||||
}
|
||||
foreach ($params as $key => $value)
|
||||
{
|
||||
$this->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the database connection/settings.
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \CodeIgniter\DatabaseException
|
||||
*/
|
||||
/**
|
||||
* Initializes the database connection/settings.
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \CodeIgniter\DatabaseException
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
/* If an established connection is available, then there's
|
||||
@ -410,28 +410,28 @@ abstract class BaseConnection implements ConnectionInterface
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close the database connection.
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
if ($this->connID)
|
||||
{
|
||||
$this->_close();
|
||||
$this->connID = FALSE;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Close the database connection.
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
if ($this->connID)
|
||||
{
|
||||
$this->_close();
|
||||
$this->connID = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Platform dependent way method for closing the connection.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function _close();
|
||||
/**
|
||||
* Platform dependent way method for closing the connection.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function _close();
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create a persistent database connection.
|
||||
@ -573,9 +573,9 @@ abstract class BaseConnection implements ConnectionInterface
|
||||
|
||||
$startTime = microtime(true);
|
||||
|
||||
// Always save the last query so we can use
|
||||
// the getLastQuery() method.
|
||||
$this->lastQuery = $query;
|
||||
// Always save the last query so we can use
|
||||
// the getLastQuery() method.
|
||||
$this->lastQuery = $query;
|
||||
|
||||
// Run the query for real
|
||||
if (! $this->pretend && false === ($this->resultID = $this->simpleQuery($query->getQuery())))
|
||||
@ -583,41 +583,41 @@ abstract class BaseConnection implements ConnectionInterface
|
||||
$query->setDuration($startTime, $startTime);
|
||||
|
||||
// This will trigger a rollback if transactions are being used
|
||||
if ($this->_trans_depth !== 0)
|
||||
{
|
||||
$this->_trans_status = false;
|
||||
}
|
||||
if ($this->_trans_depth !== 0)
|
||||
{
|
||||
$this->_trans_status = false;
|
||||
}
|
||||
|
||||
// @todo deal with errors
|
||||
|
||||
if ($this->DBDebug)
|
||||
{
|
||||
// We call this function in order to roll-back queries
|
||||
// if transactions are enabled. If we don't call this here
|
||||
// the error message will trigger an exit, causing the
|
||||
// transactions to remain in limbo.
|
||||
while ($this->_trans_depth !== 0)
|
||||
{
|
||||
$transDepth = $this->_trans_depth;
|
||||
$this->transComplete();
|
||||
if ($this->DBDebug)
|
||||
{
|
||||
// We call this function in order to roll-back queries
|
||||
// if transactions are enabled. If we don't call this here
|
||||
// the error message will trigger an exit, causing the
|
||||
// transactions to remain in limbo.
|
||||
while ($this->_trans_depth !== 0)
|
||||
{
|
||||
$transDepth = $this->_trans_depth;
|
||||
$this->transComplete();
|
||||
|
||||
if ($transDepth === $this->_trans_depth)
|
||||
{
|
||||
// @todo log
|
||||
// log_message('error', 'Database: Failure during an automated transaction commit/rollback!');
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($transDepth === $this->_trans_depth)
|
||||
{
|
||||
// @todo log
|
||||
// log_message('error', 'Database: Failure during an automated transaction commit/rollback!');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// display the errors....
|
||||
// @todo display the error...
|
||||
// display the errors....
|
||||
// @todo display the error...
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->pretend)
|
||||
{
|
||||
// Let others do something with this query.
|
||||
// Let others do something with this query.
|
||||
Hooks::trigger('DBQuery', $query);
|
||||
}
|
||||
|
||||
@ -628,8 +628,8 @@ abstract class BaseConnection implements ConnectionInterface
|
||||
|
||||
if (! $this->pretend)
|
||||
{
|
||||
// Let others do somethign with this query
|
||||
Hooks::trigger('DBQuery', $query);
|
||||
// Let others do somethign with this query
|
||||
Hooks::trigger('DBQuery', $query);
|
||||
}
|
||||
|
||||
// If $pretend is true, then we just want to return
|
||||
@ -663,217 +663,217 @@ abstract class BaseConnection implements ConnectionInterface
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Disable Transactions
|
||||
*
|
||||
* This permits transactions to be disabled at run-time.
|
||||
*/
|
||||
public function transOff()
|
||||
{
|
||||
$this->trans_enabled = FALSE;
|
||||
}
|
||||
/**
|
||||
* Disable Transactions
|
||||
*
|
||||
* This permits transactions to be disabled at run-time.
|
||||
*/
|
||||
public function transOff()
|
||||
{
|
||||
$this->trans_enabled = FALSE;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Enable/disable Transaction Strict Mode
|
||||
*
|
||||
* When strict mode is enabled, if you are running multiple groups of
|
||||
* transactions, if one group fails all subsequent groups will be
|
||||
* rolled back.
|
||||
*
|
||||
* If strict mode is disabled, each group is treated autonomously,
|
||||
* meaning a failure of one group will not affect any others
|
||||
*
|
||||
* @param bool $mode = true
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function transStrict(bool $mode=true)
|
||||
{
|
||||
$this->trans_strict = $mode;
|
||||
/**
|
||||
* Enable/disable Transaction Strict Mode
|
||||
*
|
||||
* When strict mode is enabled, if you are running multiple groups of
|
||||
* transactions, if one group fails all subsequent groups will be
|
||||
* rolled back.
|
||||
*
|
||||
* If strict mode is disabled, each group is treated autonomously,
|
||||
* meaning a failure of one group will not affect any others
|
||||
*
|
||||
* @param bool $mode = true
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function transStrict(bool $mode=true)
|
||||
{
|
||||
$this->trans_strict = $mode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Start Transaction
|
||||
*
|
||||
* @param bool $test_mode = FALSE
|
||||
* @return bool
|
||||
*/
|
||||
public function transStart($test_mode = false)
|
||||
{
|
||||
if ( ! $this->trans_enabled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Start Transaction
|
||||
*
|
||||
* @param bool $test_mode = FALSE
|
||||
* @return bool
|
||||
*/
|
||||
public function transStart($test_mode = false)
|
||||
{
|
||||
if ( ! $this->trans_enabled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->transBegin($test_mode);
|
||||
}
|
||||
return $this->transBegin($test_mode);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Complete Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function transComplete()
|
||||
{
|
||||
if ( ! $this->trans_enabled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Complete Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function transComplete()
|
||||
{
|
||||
if ( ! $this->trans_enabled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// The query() function will set this flag to FALSE in the event that a query failed
|
||||
if ($this->_trans_status === false OR $this->_trans_failure === true)
|
||||
{
|
||||
$this->transRollback();
|
||||
// The query() function will set this flag to FALSE in the event that a query failed
|
||||
if ($this->_trans_status === false OR $this->_trans_failure === true)
|
||||
{
|
||||
$this->transRollback();
|
||||
|
||||
// If we are NOT running in strict mode, we will reset
|
||||
// the _trans_status flag so that subsequent groups of
|
||||
// transactions will be permitted.
|
||||
if ($this->trans_strict === false)
|
||||
{
|
||||
$this->_trans_status = true;
|
||||
}
|
||||
// If we are NOT running in strict mode, we will reset
|
||||
// the _trans_status flag so that subsequent groups of
|
||||
// transactions will be permitted.
|
||||
if ($this->trans_strict === false)
|
||||
{
|
||||
$this->_trans_status = true;
|
||||
}
|
||||
|
||||
// log_message('debug', 'DB Transaction Failure');
|
||||
return FALSE;
|
||||
}
|
||||
// log_message('debug', 'DB Transaction Failure');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return $this->transCommit();
|
||||
}
|
||||
return $this->transCommit();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Lets you retrieve the transaction flag to determine if it has failed
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function transStatus(): bool
|
||||
{
|
||||
return $this->_trans_status;
|
||||
}
|
||||
/**
|
||||
* Lets you retrieve the transaction flag to determine if it has failed
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function transStatus(): bool
|
||||
{
|
||||
return $this->_trans_status;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @param bool $test_mode
|
||||
* @return bool
|
||||
*/
|
||||
public function transBegin(bool $test_mode = false): bool
|
||||
{
|
||||
if ( ! $this->trans_enabled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// When transactions are nested we only begin/commit/rollback the outermost ones
|
||||
elseif ($this->_trans_depth > 0)
|
||||
{
|
||||
$this->_trans_depth++;
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @param bool $test_mode
|
||||
* @return bool
|
||||
*/
|
||||
public function transBegin(bool $test_mode = false): bool
|
||||
{
|
||||
if ( ! $this->trans_enabled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// When transactions are nested we only begin/commit/rollback the outermost ones
|
||||
elseif ($this->_trans_depth > 0)
|
||||
{
|
||||
$this->_trans_depth++;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (empty($this->connID))
|
||||
{
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
// Reset the transaction failure flag.
|
||||
// If the $test_mode flag is set to TRUE transactions will be rolled back
|
||||
// even if the queries produce a successful result.
|
||||
$this->_trans_failure = ($test_mode === true);
|
||||
// Reset the transaction failure flag.
|
||||
// If the $test_mode flag is set to TRUE transactions will be rolled back
|
||||
// even if the queries produce a successful result.
|
||||
$this->_trans_failure = ($test_mode === true);
|
||||
|
||||
if ($this->_transBegin())
|
||||
{
|
||||
$this->_trans_depth++;
|
||||
return true;
|
||||
}
|
||||
if ($this->_transBegin())
|
||||
{
|
||||
$this->_trans_depth++;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function transCommit(): bool
|
||||
{
|
||||
if ( ! $this->trans_enabled || $this->_trans_depth === 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// When transactions are nested we only begin/commit/rollback the outermost ones
|
||||
elseif ($this->_trans_depth > 1 || $this->_transCommit())
|
||||
{
|
||||
$this->_trans_depth--;
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function transCommit(): bool
|
||||
{
|
||||
if ( ! $this->trans_enabled || $this->_trans_depth === 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// When transactions are nested we only begin/commit/rollback the outermost ones
|
||||
elseif ($this->_trans_depth > 1 || $this->_transCommit())
|
||||
{
|
||||
$this->_trans_depth--;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function transRollback(): bool
|
||||
{
|
||||
if ( ! $this->trans_enabled OR $this->_trans_depth === 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// When transactions are nested we only begin/commit/rollback the outermost ones
|
||||
elseif ($this->_trans_depth > 1 OR $this->_transRollback())
|
||||
{
|
||||
$this->_trans_depth--;
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function transRollback(): bool
|
||||
{
|
||||
if ( ! $this->trans_enabled OR $this->_trans_depth === 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// When transactions are nested we only begin/commit/rollback the outermost ones
|
||||
elseif ($this->_trans_depth > 1 OR $this->_transRollback())
|
||||
{
|
||||
$this->_trans_depth--;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function _transBegin(): bool;
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function _transBegin(): bool;
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function _transCommit(): bool;
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function _transCommit(): bool;
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function _transRollback(): bool;
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function _transRollback(): bool;
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an instance of the query builder for this connection.
|
||||
@ -920,7 +920,7 @@ abstract class BaseConnection implements ConnectionInterface
|
||||
{
|
||||
$this->pretend(true);
|
||||
|
||||
$sql = $func($this);
|
||||
$sql = $func($this);
|
||||
|
||||
$this->pretend(false);
|
||||
|
||||
@ -956,7 +956,7 @@ abstract class BaseConnection implements ConnectionInterface
|
||||
*/
|
||||
public function showLastQuery()
|
||||
{
|
||||
return (string)$this->lastQuery;
|
||||
return (string)$this->lastQuery;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -973,7 +973,7 @@ abstract class BaseConnection implements ConnectionInterface
|
||||
*/
|
||||
public function getConnectStart()
|
||||
{
|
||||
return $this->connectTime;
|
||||
return $this->connectTime;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -990,7 +990,7 @@ abstract class BaseConnection implements ConnectionInterface
|
||||
*/
|
||||
public function getConnectDuration($decimals = 6)
|
||||
{
|
||||
return number_format($this->connectDuration, $decimals);
|
||||
return number_format($this->connectDuration, $decimals);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -1035,7 +1035,7 @@ abstract class BaseConnection implements ConnectionInterface
|
||||
foreach ($item as $k => $v)
|
||||
{
|
||||
$escaped_array[$this->protectIdentifiers($k)] = $this->protectIdentifiers($v, $prefixSingle,
|
||||
$protectIdentifiers, $fieldExists);
|
||||
$protectIdentifiers, $fieldExists);
|
||||
}
|
||||
|
||||
return $escaped_array;
|
||||
@ -1217,8 +1217,8 @@ abstract class BaseConnection implements ConnectionInterface
|
||||
}
|
||||
// Avoid breaking functions and literal values inside queries
|
||||
elseif (ctype_digit($item) OR $item[0] === "'" OR ($this->escapeChar !== '"' && $item[0] === '"') OR
|
||||
strpos($item, '(') !== false
|
||||
)
|
||||
strpos($item, '(') !== false
|
||||
)
|
||||
{
|
||||
return $item;
|
||||
}
|
||||
@ -1248,26 +1248,26 @@ abstract class BaseConnection implements ConnectionInterface
|
||||
if (strpos($item, '.'.$id) !== false)
|
||||
{
|
||||
return preg_replace('/'.$preg_ec[0].'?([^'.$preg_ec[1].'\.]+)'.$preg_ec[1].'?\./i',
|
||||
$preg_ec[2].'$1'.$preg_ec[3].'.', $item);
|
||||
$preg_ec[2].'$1'.$preg_ec[3].'.', $item);
|
||||
}
|
||||
}
|
||||
|
||||
return preg_replace('/'.$preg_ec[0].'?([^'.$preg_ec[1].'\.]+)'.$preg_ec[1].'?(\.)?/i',
|
||||
$preg_ec[2].'$1'.$preg_ec[3].'$2', $item);
|
||||
$preg_ec[2].'$1'.$preg_ec[3].'$2', $item);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* DB Prefix
|
||||
*
|
||||
* Prepends a database prefix if one exists in configuration
|
||||
*
|
||||
* @param string $table the table
|
||||
*
|
||||
* @return string
|
||||
* @throws \CodeIgniter\DatabaseException
|
||||
*/
|
||||
/**
|
||||
* DB Prefix
|
||||
*
|
||||
* Prepends a database prefix if one exists in configuration
|
||||
*
|
||||
* @param string $table the table
|
||||
*
|
||||
* @return string
|
||||
* @throws \CodeIgniter\DatabaseException
|
||||
*/
|
||||
public function prefixTable($table = '')
|
||||
{
|
||||
if ($table === '')
|
||||
@ -1366,10 +1366,10 @@ abstract class BaseConnection implements ConnectionInterface
|
||||
if ($like === true)
|
||||
{
|
||||
return str_replace(
|
||||
[$this->likeEscapeChar, '%', '_'],
|
||||
[$this->likeEscapeChar.$this->likeEscapeChar, $this->likeEscapeChar.'%', $this->likeEscapeChar.'_'],
|
||||
$str
|
||||
);
|
||||
[$this->likeEscapeChar, '%', '_'],
|
||||
[$this->likeEscapeChar.$this->likeEscapeChar, $this->likeEscapeChar.'%', $this->likeEscapeChar.'_'],
|
||||
$str
|
||||
);
|
||||
}
|
||||
|
||||
return $str;
|
||||
@ -1637,7 +1637,7 @@ abstract class BaseConnection implements ConnectionInterface
|
||||
*/
|
||||
public function pretend(bool $pretend = true)
|
||||
{
|
||||
$this->pretend = $pretend;
|
||||
$this->pretend = $pretend;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ abstract class BasePreparedQuery implements PreparedQueryInterface
|
||||
$query->setDuration($startTime);
|
||||
|
||||
// Let others do something with this query
|
||||
Hooks::trigger('DBQuery', $query);
|
||||
Hooks::trigger('DBQuery', $query);
|
||||
|
||||
// Return a result object
|
||||
$resultClass = str_replace('PreparedQuery', 'Result', get_class($this));
|
||||
@ -196,7 +196,7 @@ abstract class BasePreparedQuery implements PreparedQueryInterface
|
||||
return;
|
||||
}
|
||||
|
||||
$this->statement->close();
|
||||
$this->statement->close();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -208,10 +208,10 @@ abstract class BasePreparedQuery implements PreparedQueryInterface
|
||||
*/
|
||||
public function getQueryString(): string
|
||||
{
|
||||
if (! $this->query instanceof QueryInterface)
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot call getQueryString on a prepared query until after the query has been prepared.');
|
||||
}
|
||||
if (! $this->query instanceof QueryInterface)
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot call getQueryString on a prepared query until after the query has been prepared.');
|
||||
}
|
||||
|
||||
return $this->query->getQuery();
|
||||
}
|
||||
@ -225,7 +225,7 @@ abstract class BasePreparedQuery implements PreparedQueryInterface
|
||||
*/
|
||||
public function hasError()
|
||||
{
|
||||
return ! empty($this->errorString);
|
||||
return ! empty($this->errorString);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
@ -173,7 +173,7 @@ class Forge
|
||||
*/
|
||||
public function getConnection()
|
||||
{
|
||||
return $this->db;
|
||||
return $this->db;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -198,8 +198,8 @@ class Forge
|
||||
return false;
|
||||
}
|
||||
elseif ( ! $this->db->query(sprintf($this->createDatabaseStr, $db_name, $this->db->charset,
|
||||
$this->db->DBCollat))
|
||||
)
|
||||
$this->db->DBCollat))
|
||||
)
|
||||
{
|
||||
if ($this->db->DBDebug)
|
||||
{
|
||||
@ -302,11 +302,11 @@ class Forge
|
||||
if ($field === 'id')
|
||||
{
|
||||
$this->addField([
|
||||
'id' => [
|
||||
'id' => [
|
||||
'type' => 'INT',
|
||||
'constraint' => 9,
|
||||
'auto_increment' => true,
|
||||
],
|
||||
],
|
||||
]);
|
||||
$this->addKey('id', true);
|
||||
}
|
||||
@ -331,16 +331,16 @@ class Forge
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create Table
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @param bool $if_not_exists Whether to add IF NOT EXISTS condition
|
||||
* @param array $attributes Associative array of table attributes
|
||||
*
|
||||
* @return bool
|
||||
* @throws \CodeIgniter\DatabaseException
|
||||
*/
|
||||
/**
|
||||
* Create Table
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @param bool $if_not_exists Whether to add IF NOT EXISTS condition
|
||||
* @param array $attributes Associative array of table attributes
|
||||
*
|
||||
* @return bool
|
||||
* @throws \CodeIgniter\DatabaseException
|
||||
*/
|
||||
public function createTable($table, $if_not_exists = false, array $attributes = [])
|
||||
{
|
||||
if ($table === '')
|
||||
@ -430,7 +430,7 @@ class Forge
|
||||
}
|
||||
|
||||
$columns = implode(',', $columns)
|
||||
.$this->_processPrimaryKeys($table);
|
||||
.$this->_processPrimaryKeys($table);
|
||||
|
||||
// Are indexes created from within the CREATE TABLE statement? (e.g. in MySQL)
|
||||
if ($this->createTableKeys === true)
|
||||
@ -440,11 +440,11 @@ class Forge
|
||||
|
||||
// createTableStr will usually have the following format: "%s %s (%s\n)"
|
||||
$sql = sprintf($this->createTableStr.'%s',
|
||||
$sql,
|
||||
$this->db->escapeIdentifiers($table),
|
||||
$columns,
|
||||
$this->_createTableAttributes($attributes)
|
||||
);
|
||||
$sql,
|
||||
$this->db->escapeIdentifiers($table),
|
||||
$columns,
|
||||
$this->_createTableAttributes($attributes)
|
||||
);
|
||||
|
||||
return $sql;
|
||||
}
|
||||
@ -506,7 +506,7 @@ class Forge
|
||||
if ($query && ! empty($this->db->dataCache['table_names']))
|
||||
{
|
||||
$key = array_search(strtolower($this->db->DBPrefix.$table_name),
|
||||
array_map('strtolower', $this->db->dataCache['table_names']), true);
|
||||
array_map('strtolower', $this->db->dataCache['table_names']), true);
|
||||
if ($key !== false)
|
||||
{
|
||||
unset($this->db->dataCache['table_names'][$key]);
|
||||
@ -577,14 +577,14 @@ class Forge
|
||||
}
|
||||
|
||||
$result = $this->db->query(sprintf($this->renameTableStr,
|
||||
$this->db->escapeIdentifiers($this->db->DBPrefix.$table_name),
|
||||
$this->db->escapeIdentifiers($this->db->DBPrefix.$new_table_name))
|
||||
);
|
||||
$this->db->escapeIdentifiers($this->db->DBPrefix.$table_name),
|
||||
$this->db->escapeIdentifiers($this->db->DBPrefix.$new_table_name))
|
||||
);
|
||||
|
||||
if ($result && ! empty($this->db->dataCache['table_names']))
|
||||
{
|
||||
$key = array_search(strtolower($this->db->DBPrefix.$table_name),
|
||||
array_map('strtolower', $this->db->dataCache['table_names']), true);
|
||||
array_map('strtolower', $this->db->dataCache['table_names']), true);
|
||||
if ($key !== false)
|
||||
{
|
||||
$this->db->dataCache['table_names'][$key] = $this->db->DBPrefix.$new_table_name;
|
||||
@ -741,7 +741,7 @@ class Forge
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
$sqls[] = $sql
|
||||
.($field[$i]['_literal'] !== false ? $field[$i]['_literal'] : $this->_processColumn($field[$i]));
|
||||
.($field[$i]['_literal'] !== false ? $field[$i]['_literal'] : $this->_processColumn($field[$i]));
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
@ -867,12 +867,12 @@ class Forge
|
||||
protected function _processColumn($field)
|
||||
{
|
||||
return $this->db->escapeIdentifiers($field['name'])
|
||||
.' '.$field['type'].$field['length']
|
||||
.$field['unsigned']
|
||||
.$field['default']
|
||||
.$field['null']
|
||||
.$field['auto_increment']
|
||||
.$field['unique'];
|
||||
.' '.$field['type'].$field['length']
|
||||
.$field['unsigned']
|
||||
.$field['default']
|
||||
.$field['null']
|
||||
.$field['auto_increment']
|
||||
.$field['unique'];
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -1009,8 +1009,8 @@ class Forge
|
||||
protected function _attributeAutoIncrement(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === true &&
|
||||
stripos($field['type'], 'int') !== false
|
||||
)
|
||||
stripos($field['type'], 'int') !== false
|
||||
)
|
||||
{
|
||||
$field['auto_increment'] = ' AUTO_INCREMENT';
|
||||
}
|
||||
@ -1040,62 +1040,62 @@ class Forge
|
||||
if (count($this->primaryKeys) > 0)
|
||||
{
|
||||
$sql .= ",\n\tCONSTRAINT ".$this->db->escapeIdentifiers('pk_'.$table)
|
||||
.' PRIMARY KEY('.implode(', ', $this->db->escapeIdentifiers($this->primaryKeys)).')';
|
||||
}
|
||||
.' PRIMARY KEY('.implode(', ', $this->db->escapeIdentifiers($this->primaryKeys)).')';
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process indexes
|
||||
*
|
||||
* @param string $table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _processIndexes($table)
|
||||
{
|
||||
$sqls = [];
|
||||
/**
|
||||
* Process indexes
|
||||
*
|
||||
* @param string $table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _processIndexes($table)
|
||||
{
|
||||
$sqls = [];
|
||||
|
||||
for ($i = 0, $c = count($this->keys); $i < $c; $i++)
|
||||
{
|
||||
$this->keys[$i] = (array) $this->keys[$i];
|
||||
for ($i = 0, $c = count($this->keys); $i < $c; $i++)
|
||||
{
|
||||
$this->keys[$i] = (array) $this->keys[$i];
|
||||
|
||||
for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++)
|
||||
for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++)
|
||||
{
|
||||
if ( ! isset($this->fields[$this->keys[$i][$i2]]))
|
||||
{
|
||||
unset($this->keys[$i][$i2]);
|
||||
}
|
||||
}
|
||||
if (count($this->keys[$i]) <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$sqls[] = 'CREATE INDEX '.$this->db->escapeIdentifiers($table.'_'.implode('_', $this->keys[$i]))
|
||||
.' ON '.$this->db->escapeIdentifiers($table)
|
||||
.' ('.implode(', ', $this->db->escapeIdentifiers($this->keys[$i])).');';
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Reset
|
||||
*
|
||||
* Resets table creation vars
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _reset()
|
||||
{
|
||||
if ( ! isset($this->fields[$this->keys[$i][$i2]]))
|
||||
{
|
||||
unset($this->keys[$i][$i2]);
|
||||
}
|
||||
$this->fields = $this->keys = $this->primaryKeys = [];
|
||||
}
|
||||
if (count($this->keys[$i]) <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$sqls[] = 'CREATE INDEX '.$this->db->escapeIdentifiers($table.'_'.implode('_', $this->keys[$i]))
|
||||
.' ON '.$this->db->escapeIdentifiers($table)
|
||||
.' ('.implode(', ', $this->db->escapeIdentifiers($this->keys[$i])).');';
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Reset
|
||||
*
|
||||
* Resets table creation vars
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _reset()
|
||||
{
|
||||
$this->fields = $this->keys = $this->primaryKeys = [];
|
||||
}
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -121,21 +121,21 @@ class Connection extends BaseConnection implements ConnectionInterface
|
||||
if ($this->strictOn)
|
||||
{
|
||||
$this->mysqli->options(MYSQLI_INIT_COMMAND,
|
||||
'SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")');
|
||||
'SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->mysqli->options(MYSQLI_INIT_COMMAND,
|
||||
'SET SESSION sql_mode =
|
||||
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
|
||||
@@sql_mode,
|
||||
"STRICT_ALL_TABLES,", ""),
|
||||
",STRICT_ALL_TABLES", ""),
|
||||
"STRICT_ALL_TABLES", ""),
|
||||
"STRICT_TRANS_TABLES,", ""),
|
||||
",STRICT_TRANS_TABLES", ""),
|
||||
"STRICT_TRANS_TABLES", "")'
|
||||
);
|
||||
'SET SESSION sql_mode =
|
||||
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
|
||||
@@sql_mode,
|
||||
"STRICT_ALL_TABLES,", ""),
|
||||
",STRICT_ALL_TABLES", ""),
|
||||
"STRICT_ALL_TABLES", ""),
|
||||
"STRICT_TRANS_TABLES,", ""),
|
||||
",STRICT_TRANS_TABLES", ""),
|
||||
"STRICT_TRANS_TABLES", "")'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,7 +155,7 @@ class Connection extends BaseConnection implements ConnectionInterface
|
||||
if ($this->encrypt['ssl_verify'])
|
||||
{
|
||||
defined('MYSQLI_OPT_SSL_VERIFY_SERVER_CERT') &&
|
||||
$this->mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true);
|
||||
$this->mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true);
|
||||
}
|
||||
// Apparently (when it exists), setting MYSQLI_OPT_SSL_VERIFY_SERVER_CERT
|
||||
// to FALSE didn't do anything, so PHP 5.6.16 introduced yet another
|
||||
@ -171,26 +171,26 @@ class Connection extends BaseConnection implements ConnectionInterface
|
||||
|
||||
$client_flags |= MYSQLI_CLIENT_SSL;
|
||||
$this->mysqli->ssl_set(
|
||||
isset($ssl['key']) ? $ssl['key'] : null,
|
||||
isset($ssl['cert']) ? $ssl['cert'] : null,
|
||||
isset($ssl['ca']) ? $ssl['ca'] : null,
|
||||
isset($ssl['capath']) ? $ssl['capath'] : null,
|
||||
isset($ssl['cipher']) ? $ssl['cipher'] : null
|
||||
);
|
||||
isset($ssl['key']) ? $ssl['key'] : null,
|
||||
isset($ssl['cert']) ? $ssl['cert'] : null,
|
||||
isset($ssl['ca']) ? $ssl['ca'] : null,
|
||||
isset($ssl['capath']) ? $ssl['capath'] : null,
|
||||
isset($ssl['cipher']) ? $ssl['cipher'] : null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->mysqli->real_connect($hostname, $this->username, $this->password, $this->database, $port, $socket,
|
||||
$client_flags)
|
||||
)
|
||||
$client_flags)
|
||||
)
|
||||
{
|
||||
// Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails
|
||||
if (
|
||||
($client_flags & MYSQLI_CLIENT_SSL)
|
||||
&& version_compare($this->mysqli->client_info, '5.7.3', '<=')
|
||||
&& empty($this->mysqli->query("SHOW STATUS LIKE 'ssl_cipher'")
|
||||
->fetch_object()->Value)
|
||||
)
|
||||
($client_flags & MYSQLI_CLIENT_SSL)
|
||||
&& version_compare($this->mysqli->client_info, '5.7.3', '<=')
|
||||
&& empty($this->mysqli->query("SHOW STATUS LIKE 'ssl_cipher'")
|
||||
->fetch_object()->Value)
|
||||
)
|
||||
{
|
||||
$this->mysqli->close();
|
||||
$message = 'MySQLi was configured for an SSL connection, but got an unencrypted connection instead!';
|
||||
@ -239,15 +239,15 @@ class Connection extends BaseConnection implements ConnectionInterface
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close the database connection.
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
$this->connID->close();
|
||||
}
|
||||
/**
|
||||
* Close the database connection.
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
$this->connID->close();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Select a specific database table to use.
|
||||
@ -288,9 +288,9 @@ class Connection extends BaseConnection implements ConnectionInterface
|
||||
}
|
||||
|
||||
if (empty($this->mysqli))
|
||||
{
|
||||
$this->initialize();
|
||||
}
|
||||
{
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
return $this->dataCache['version'] = $this->mysqli->server_info;
|
||||
}
|
||||
@ -420,9 +420,9 @@ class Connection extends BaseConnection implements ConnectionInterface
|
||||
$retval[$i]->name = $query[$i]->Field;
|
||||
|
||||
sscanf($query[$i]->Type, '%[a-z](%d)',
|
||||
$retval[$i]->type,
|
||||
$retval[$i]->max_length
|
||||
);
|
||||
$retval[$i]->type,
|
||||
$retval[$i]->max_length
|
||||
);
|
||||
|
||||
$retval[$i]->default = $query[$i]->Default;
|
||||
$retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI');
|
||||
@ -498,9 +498,9 @@ class Connection extends BaseConnection implements ConnectionInterface
|
||||
if ( ! empty($this->mysqli->connect_errno))
|
||||
{
|
||||
return array(
|
||||
'code' => $this->mysqli->connect_errno,
|
||||
'message' => $this->_mysqli->connect_error
|
||||
);
|
||||
'code' => $this->mysqli->connect_errno,
|
||||
'message' => $this->_mysqli->connect_error
|
||||
);
|
||||
}
|
||||
|
||||
return array('code' => $this->connID->errno, 'message' => $this->connID->error);
|
||||
@ -520,53 +520,53 @@ class Connection extends BaseConnection implements ConnectionInterface
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _transBegin():bool
|
||||
{
|
||||
$this->connID->autocommit(false);
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _transBegin():bool
|
||||
{
|
||||
$this->connID->autocommit(false);
|
||||
|
||||
return $this->connID->begin_transaction();
|
||||
}
|
||||
return $this->connID->begin_transaction();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _transCommit(): bool
|
||||
{
|
||||
if ($this->connID->commit())
|
||||
{
|
||||
$this->connID->autocommit(true);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _transCommit(): bool
|
||||
{
|
||||
if ($this->connID->commit())
|
||||
{
|
||||
$this->connID->autocommit(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _transRollback(): bool
|
||||
{
|
||||
if ($this->connID->rollback())
|
||||
{
|
||||
$this->connID->autocommit(true);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _transRollback(): bool
|
||||
{
|
||||
if ($this->connID->rollback())
|
||||
{
|
||||
$this->connID->autocommit(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
}
|
||||
|
@ -83,25 +83,25 @@ class Connection extends BaseConnection implements ConnectionInterface
|
||||
$this->buildDSN();
|
||||
}
|
||||
|
||||
// Strip pgsql if exists
|
||||
if (mb_strpos($this->DSN, 'pgsql:') === 0)
|
||||
{
|
||||
$this->DSN = mb_substr($this->DSN, 6);
|
||||
}
|
||||
// Strip pgsql if exists
|
||||
if (mb_strpos($this->DSN, 'pgsql:') === 0)
|
||||
{
|
||||
$this->DSN = mb_substr($this->DSN, 6);
|
||||
}
|
||||
|
||||
// Convert semicolons to spaces.
|
||||
$this->DSN = str_replace(';', ' ', $this->DSN);
|
||||
// Convert semicolons to spaces.
|
||||
$this->DSN = str_replace(';', ' ', $this->DSN);
|
||||
|
||||
$this->connID = $persistent === true
|
||||
? pg_pconnect($this->DSN)
|
||||
: pg_connect($this->DSN);
|
||||
: pg_connect($this->DSN);
|
||||
|
||||
if ($this->connID !== false)
|
||||
{
|
||||
if ($persistent === true
|
||||
&& pg_connection_status($this->connID) === PGSQL_CONNECTION_BAD
|
||||
&& pg_ping($this->connID) === false
|
||||
)
|
||||
&& pg_connection_status($this->connID) === PGSQL_CONNECTION_BAD
|
||||
&& pg_ping($this->connID) === false
|
||||
)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -135,15 +135,15 @@ class Connection extends BaseConnection implements ConnectionInterface
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close the database connection.
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
pg_close($this->connID);
|
||||
}
|
||||
/**
|
||||
* Close the database connection.
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
pg_close($this->connID);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Select a specific database table to use.
|
||||
@ -331,7 +331,7 @@ class Connection extends BaseConnection implements ConnectionInterface
|
||||
$sql = 'SELECT "indexname", "indexdef"
|
||||
FROM "pg_indexes"
|
||||
WHERE LOWER("tablename") = '.$this->escape(strtolower($table)).'
|
||||
AND "schemaname" = '.$this->escape('public');
|
||||
AND "schemaname" = '.$this->escape('public');
|
||||
|
||||
if (($query = $this->query($sql)) === false)
|
||||
{
|
||||
@ -486,39 +486,39 @@ class Connection extends BaseConnection implements ConnectionInterface
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _transBegin(): bool
|
||||
{
|
||||
return (bool)pg_query($this->connID, 'BEGIN');
|
||||
}
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _transBegin(): bool
|
||||
{
|
||||
return (bool)pg_query($this->connID, 'BEGIN');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _transCommit(): bool
|
||||
{
|
||||
return (bool)pg_query($this->connID, 'COMMIT');
|
||||
}
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _transCommit(): bool
|
||||
{
|
||||
return (bool)pg_query($this->connID, 'COMMIT');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _transRollback(): bool
|
||||
{
|
||||
return (bool)pg_query($this->connID, 'ROLLBACK');
|
||||
}
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _transRollback(): bool
|
||||
{
|
||||
return (bool)pg_query($this->connID, 'ROLLBACK');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// --------------------------------------------------------------------
|
||||
}
|
||||
|
@ -78,8 +78,8 @@ class PreparedQuery extends BasePreparedQuery implements PreparedQueryInterface
|
||||
$sql = $this->parameterize($sql);
|
||||
|
||||
// Update the query object since the parameters are slightly different
|
||||
// than what was put in.
|
||||
$this->query->setQuery($sql);
|
||||
// than what was put in.
|
||||
$this->query->setQuery($sql);
|
||||
|
||||
if (! $this->statement = pg_prepare($this->db->connID, $this->name, $sql))
|
||||
{
|
||||
@ -140,11 +140,11 @@ class PreparedQuery extends BasePreparedQuery implements PreparedQueryInterface
|
||||
$count = 0;
|
||||
|
||||
$sql = preg_replace_callback('/\?/', function($matches) use (&$count){
|
||||
$count++;
|
||||
return "\${$count}";
|
||||
}, $sql);
|
||||
$count++;
|
||||
return "\${$count}";
|
||||
}, $sql);
|
||||
|
||||
return $sql;
|
||||
return $sql;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
@ -120,7 +120,7 @@ class Query implements QueryInterface
|
||||
*/
|
||||
public function __construct(&$db)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -157,7 +157,7 @@ class Query implements QueryInterface
|
||||
*/
|
||||
public function setBinds(array $binds)
|
||||
{
|
||||
$this->binds = $binds;
|
||||
$this->binds = $binds;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -304,8 +304,8 @@ class Query implements QueryInterface
|
||||
public function isWriteType(): bool
|
||||
{
|
||||
return (bool)preg_match(
|
||||
'/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|REINDEX)\s/i',
|
||||
$this->originalQueryString);
|
||||
'/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|REINDEX)\s/i',
|
||||
$this->originalQueryString);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -336,7 +336,7 @@ class Query implements QueryInterface
|
||||
*/
|
||||
public function getOriginalQuery()
|
||||
{
|
||||
return $this->originalQueryString;
|
||||
return $this->originalQueryString;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -351,9 +351,9 @@ class Query implements QueryInterface
|
||||
$hasNamedBinds = strpos($sql, ':') !== false;
|
||||
|
||||
if (empty($this->binds) || empty($this->bindMarker) ||
|
||||
(strpos($sql, $this->bindMarker) === false &&
|
||||
$hasNamedBinds === false)
|
||||
)
|
||||
(strpos($sql, $this->bindMarker) === false &&
|
||||
$hasNamedBinds === false)
|
||||
)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -405,24 +405,24 @@ class Query implements QueryInterface
|
||||
{
|
||||
$escapedValue = $this->db->escape($value);
|
||||
|
||||
// In order to correctly handle backlashes in saved strings
|
||||
// we will need to preg_quote, so remove the wrapping escape characters
|
||||
// otherwise it will get escaped.
|
||||
if (is_array($value))
|
||||
{
|
||||
foreach ($value as &$item)
|
||||
{
|
||||
$item = preg_quote($item);
|
||||
}
|
||||
// In order to correctly handle backlashes in saved strings
|
||||
// we will need to preg_quote, so remove the wrapping escape characters
|
||||
// otherwise it will get escaped.
|
||||
if (is_array($value))
|
||||
{
|
||||
foreach ($value as &$item)
|
||||
{
|
||||
$item = preg_quote($item);
|
||||
}
|
||||
|
||||
$escapedValue = '('.implode(',', $escapedValue).')';
|
||||
}
|
||||
else
|
||||
{
|
||||
$escapedValue = strpos($escapedValue, '\\') !== false
|
||||
? preg_quote(trim($escapedValue, $this->db->escapeChar))
|
||||
: $escapedValue;
|
||||
}
|
||||
$escapedValue = '('.implode(',', $escapedValue).')';
|
||||
}
|
||||
else
|
||||
{
|
||||
$escapedValue = strpos($escapedValue, '\\') !== false
|
||||
? preg_quote(trim($escapedValue, $this->db->escapeChar))
|
||||
: $escapedValue;
|
||||
}
|
||||
|
||||
$sql = preg_replace('/:'.$placeholder.'(?!\w)/', $escapedValue, $sql);
|
||||
}
|
||||
@ -446,10 +446,10 @@ class Query implements QueryInterface
|
||||
if ($c = preg_match_all("/'[^']*'/i", $sql, $matches))
|
||||
{
|
||||
$c = preg_match_all('/'.preg_quote($this->bindMarker, '/').'/i',
|
||||
str_replace($matches[0],
|
||||
str_replace($this->bindMarker, str_repeat(' ', $ml), $matches[0]),
|
||||
$sql, $c),
|
||||
$matches, PREG_OFFSET_CAPTURE);
|
||||
str_replace($matches[0],
|
||||
str_replace($this->bindMarker, str_repeat(' ', $ml), $matches[0]),
|
||||
$sql, $c),
|
||||
$matches, PREG_OFFSET_CAPTURE);
|
||||
|
||||
// Bind values' count must match the count of markers in the query
|
||||
if ($bindCount !== $c)
|
||||
@ -459,7 +459,7 @@ class Query implements QueryInterface
|
||||
}
|
||||
// Number of binds must match bindMarkers in the string.
|
||||
else if (($c = preg_match_all('/'.preg_quote($this->bindMarker, '/').'/i', $sql, $matches,
|
||||
PREG_OFFSET_CAPTURE)) !== $bindCount)
|
||||
PREG_OFFSET_CAPTURE)) !== $bindCount)
|
||||
{
|
||||
return $sql;
|
||||
}
|
||||
@ -488,7 +488,7 @@ class Query implements QueryInterface
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getQuery();
|
||||
return $this->getQuery();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
@ -90,7 +90,7 @@ class Seeder
|
||||
*/
|
||||
public function __construct(BaseConfig $config, BaseConnection $db = null)
|
||||
{
|
||||
$this->seedPath = $config->filesPath ?? APPPATH.'Database/';
|
||||
$this->seedPath = $config->filesPath ?? APPPATH.'Database/';
|
||||
|
||||
if (empty($this->seedPath))
|
||||
{
|
||||
@ -125,35 +125,35 @@ class Seeder
|
||||
*/
|
||||
public function call(string $class)
|
||||
{
|
||||
if (empty($class))
|
||||
{
|
||||
if (empty($class))
|
||||
{
|
||||
throw new \InvalidArgumentException('No Seeder was specified.');
|
||||
}
|
||||
}
|
||||
|
||||
$path = str_replace('.php', '', $class).'.php';
|
||||
|
||||
// If we have namespaced class, simply try to load it.
|
||||
if (strpos($class, '\\') !== false)
|
||||
{
|
||||
$seeder = new $class($this->config);
|
||||
}
|
||||
// Otherwise, try to load the class manually.
|
||||
else
|
||||
{
|
||||
$path = $this->seedPath.$path;
|
||||
// If we have namespaced class, simply try to load it.
|
||||
if (strpos($class, '\\') !== false)
|
||||
{
|
||||
$seeder = new $class($this->config);
|
||||
}
|
||||
// Otherwise, try to load the class manually.
|
||||
else
|
||||
{
|
||||
$path = $this->seedPath.$path;
|
||||
|
||||
if (! is_file($path))
|
||||
{
|
||||
throw new \InvalidArgumentException('The specified Seeder is not a valid file: '. $path);
|
||||
}
|
||||
if (! is_file($path))
|
||||
{
|
||||
throw new \InvalidArgumentException('The specified Seeder is not a valid file: '. $path);
|
||||
}
|
||||
|
||||
if (! class_exists($class, false))
|
||||
{
|
||||
require $path;
|
||||
}
|
||||
if (! class_exists($class, false))
|
||||
{
|
||||
require $path;
|
||||
}
|
||||
|
||||
$seeder = new $class($this->config);
|
||||
}
|
||||
$seeder = new $class($this->config);
|
||||
}
|
||||
|
||||
$seeder->run();
|
||||
|
||||
@ -192,7 +192,7 @@ class Seeder
|
||||
*/
|
||||
public function setSilent(bool $silent)
|
||||
{
|
||||
$this->silent = $silent;
|
||||
$this->silent = $silent;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -79,13 +79,13 @@ class Database extends BaseCollector
|
||||
*/
|
||||
protected $connections;
|
||||
|
||||
/**
|
||||
* The query instances that have been collected
|
||||
* through the DBQuery Hook.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $queries = [];
|
||||
/**
|
||||
* The query instances that have been collected
|
||||
* through the DBQuery Hook.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $queries = [];
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -100,20 +100,20 @@ class Database extends BaseCollector
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The static method used during Hooks to collect
|
||||
* data.
|
||||
*
|
||||
* @param \CodeIgniter\Database\Query $query
|
||||
*
|
||||
* @internal param $ array \CodeIgniter\Database\Query
|
||||
*/
|
||||
public static function collect(Query $query)
|
||||
{
|
||||
static::$queries[] = $query;
|
||||
}
|
||||
/**
|
||||
* The static method used during Hooks to collect
|
||||
* data.
|
||||
*
|
||||
* @param \CodeIgniter\Database\Query $query
|
||||
*
|
||||
* @internal param $ array \CodeIgniter\Database\Query
|
||||
*/
|
||||
public static function collect(Query $query)
|
||||
{
|
||||
static::$queries[] = $query;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns timeline data formatted for the toolbar.
|
||||
@ -135,15 +135,15 @@ class Database extends BaseCollector
|
||||
];
|
||||
}
|
||||
|
||||
foreach (static::$queries as $query)
|
||||
{
|
||||
$data[] = [
|
||||
'name' => 'Query',
|
||||
'component' => 'Database',
|
||||
'start' => $query->getStartTime(true),
|
||||
'duration' => $query->getDuration()
|
||||
];
|
||||
}
|
||||
foreach (static::$queries as $query)
|
||||
{
|
||||
$data[] = [
|
||||
'name' => 'Query',
|
||||
'component' => 'Database',
|
||||
'start' => $query->getStartTime(true),
|
||||
'duration' => $query->getDuration()
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
@ -157,35 +157,35 @@ class Database extends BaseCollector
|
||||
*/
|
||||
public function display(): string
|
||||
{
|
||||
// Key words we want bolded
|
||||
$highlight = ['SELECT', 'DISTINCT', 'FROM', 'WHERE', 'AND', 'LEFT JOIN', 'ORDER BY', 'GROUP BY',
|
||||
'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'OR ', 'HAVING', 'OFFSET', 'NOT IN',
|
||||
'IN', 'LIKE', 'NOT LIKE', 'COUNT', 'MAX', 'MIN', 'ON', 'AS', 'AVG', 'SUM', '(', ')'
|
||||
];
|
||||
// Key words we want bolded
|
||||
$highlight = ['SELECT', 'DISTINCT', 'FROM', 'WHERE', 'AND', 'LEFT JOIN', 'ORDER BY', 'GROUP BY',
|
||||
'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'OR ', 'HAVING', 'OFFSET', 'NOT IN',
|
||||
'IN', 'LIKE', 'NOT LIKE', 'COUNT', 'MAX', 'MIN', 'ON', 'AS', 'AVG', 'SUM', '(', ')'
|
||||
];
|
||||
|
||||
$parser = \Config\Services::parser(BASEPATH.'Debug/Toolbar/Views/');
|
||||
|
||||
$data = [
|
||||
'queries' => []
|
||||
];
|
||||
'queries' => []
|
||||
];
|
||||
|
||||
foreach (static::$queries as $query)
|
||||
{
|
||||
$sql = $query->getQuery();
|
||||
{
|
||||
$sql = $query->getQuery();
|
||||
|
||||
foreach ($highlight as $term)
|
||||
{
|
||||
$sql = str_replace($term, "<strong>{$term}</strong>", $sql);
|
||||
}
|
||||
foreach ($highlight as $term)
|
||||
{
|
||||
$sql = str_replace($term, "<strong>{$term}</strong>", $sql);
|
||||
}
|
||||
|
||||
$data['queries'][] = [
|
||||
'duration' => $query->getDuration(5) * 1000,
|
||||
'sql' => $sql
|
||||
];
|
||||
}
|
||||
$data['queries'][] = [
|
||||
'duration' => $query->getDuration(5) * 1000,
|
||||
'sql' => $sql
|
||||
];
|
||||
}
|
||||
|
||||
$output = $parser->setData($data)
|
||||
->render('_database.tpl');
|
||||
->render('_database.tpl');
|
||||
|
||||
return $output;
|
||||
}
|
||||
@ -200,7 +200,7 @@ class Database extends BaseCollector
|
||||
public function getTitleDetails(): string
|
||||
{
|
||||
return '('.count(static::$queries).' Queries across '.count($this->connections).' Connection'.
|
||||
(count($this->connections) > 1 ? 's' : '').')';
|
||||
(count($this->connections) > 1 ? 's' : '').')';
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
@ -85,13 +85,13 @@ class Files extends BaseCollector
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function display(): string
|
||||
{
|
||||
$parser = \Config\Services::parser(BASEPATH.'Debug/Toolbar/Views/');
|
||||
public function display(): string
|
||||
{
|
||||
$parser = \Config\Services::parser(BASEPATH.'Debug/Toolbar/Views/');
|
||||
|
||||
$rawFiles = get_included_files();
|
||||
$coreFiles = [];
|
||||
$userFiles = [];
|
||||
$rawFiles = get_included_files();
|
||||
$coreFiles = [];
|
||||
$userFiles = [];
|
||||
|
||||
foreach ($rawFiles as $file)
|
||||
{
|
||||
@ -100,16 +100,16 @@ class Files extends BaseCollector
|
||||
if (strpos($path, 'BASEPATH') !== false)
|
||||
{
|
||||
$coreFiles[] = [
|
||||
'name' => basename($file),
|
||||
'path' => $path
|
||||
];
|
||||
'name' => basename($file),
|
||||
'path' => $path
|
||||
];
|
||||
}
|
||||
else
|
||||
{
|
||||
$userFiles[] = [
|
||||
'name' => basename($file),
|
||||
'path' => $path
|
||||
];
|
||||
$userFiles[] = [
|
||||
'name' => basename($file),
|
||||
'path' => $path
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,11 +117,11 @@ class Files extends BaseCollector
|
||||
sort($coreFiles);
|
||||
|
||||
return $parser->setData([
|
||||
'coreFiles' => $coreFiles,
|
||||
'userFiles' => $userFiles,
|
||||
])
|
||||
->render('_files.tpl');
|
||||
}
|
||||
'coreFiles' => $coreFiles,
|
||||
'userFiles' => $userFiles,
|
||||
])
|
||||
->render('_files.tpl');
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ class Logs extends BaseCollector
|
||||
*/
|
||||
public function display(): string
|
||||
{
|
||||
$parser = \Config\Services::parser(BASEPATH.'Debug/Toolbar/Views/');
|
||||
$parser = \Config\Services::parser(BASEPATH.'Debug/Toolbar/Views/');
|
||||
|
||||
$logger = Services::logger(true);
|
||||
$logs = $logger->logCache;
|
||||
@ -88,9 +88,9 @@ class Logs extends BaseCollector
|
||||
}
|
||||
|
||||
return $parser->setData([
|
||||
'logs' => $logs
|
||||
])
|
||||
->render('_logs.tpl');
|
||||
'logs' => $logs
|
||||
])
|
||||
->render('_logs.tpl');
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
@ -70,14 +70,14 @@ class Routes extends BaseCollector
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Builds and returns the HTML needed to fill a tab to display
|
||||
* within the Debug Bar
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
* Builds and returns the HTML needed to fill a tab to display
|
||||
* within the Debug Bar
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function display(): string
|
||||
{
|
||||
$parser = \Config\Services::parser();
|
||||
$parser = \Config\Services::parser();
|
||||
|
||||
$rawRoutes = Services::routes(true);
|
||||
$router = Services::router(null, true);
|
||||
@ -91,46 +91,46 @@ class Routes extends BaseCollector
|
||||
$method = is_callable($router->controllerName()) ? new \ReflectionFunction($router->controllerName()) : new \ReflectionMethod($router->controllerName(), $router->methodName());
|
||||
$rawParams = $method->getParameters();
|
||||
|
||||
$params = [];
|
||||
foreach ($rawParams as $key => $param)
|
||||
{
|
||||
$params[] = [
|
||||
'name' => $param->getName(),
|
||||
'value' => $router->params()[$key] ?:
|
||||
"<empty> | default: ". var_export($param->getDefaultValue(), true)
|
||||
];
|
||||
}
|
||||
$params = [];
|
||||
foreach ($rawParams as $key => $param)
|
||||
{
|
||||
$params[] = [
|
||||
'name' => $param->getName(),
|
||||
'value' => $router->params()[$key] ?:
|
||||
"<empty> | default: ". var_export($param->getDefaultValue(), true)
|
||||
];
|
||||
}
|
||||
|
||||
$matchedRoute = [
|
||||
[
|
||||
'directory' => $router->directory(),
|
||||
'controller' => $router->controllerName(),
|
||||
'method' => $router->methodName(),
|
||||
'paramCount' => count($router->params()),
|
||||
'truePCount' => count($params),
|
||||
'params' => $params ?? []
|
||||
]
|
||||
];
|
||||
[
|
||||
'directory' => $router->directory(),
|
||||
'controller' => $router->controllerName(),
|
||||
'method' => $router->methodName(),
|
||||
'paramCount' => count($router->params()),
|
||||
'truePCount' => count($params),
|
||||
'params' => $params ?? []
|
||||
]
|
||||
];
|
||||
|
||||
/*
|
||||
* Defined Routes
|
||||
*/
|
||||
/*
|
||||
* Defined Routes
|
||||
*/
|
||||
$rawRoutes = $rawRoutes->getRoutes();
|
||||
$routes = [];
|
||||
|
||||
foreach ($rawRoutes as $from => $to)
|
||||
{
|
||||
$routes[] = [
|
||||
'from' => $from,
|
||||
'to' => $to
|
||||
];
|
||||
$routes[] = [
|
||||
'from' => $from,
|
||||
'to' => $to
|
||||
];
|
||||
}
|
||||
|
||||
return $parser->setData([
|
||||
'matchedRoute' => $matchedRoute,
|
||||
'routes' => $routes
|
||||
])
|
||||
->render('CodeIgniter\Debug\Toolbar\Views\_routes.tpl');
|
||||
'matchedRoute' => $matchedRoute,
|
||||
'routes' => $routes
|
||||
])
|
||||
->render('CodeIgniter\Debug\Toolbar\Views\_routes.tpl');
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
446
system/Model.php
446
system/Model.php
@ -191,37 +191,37 @@ class Model
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
/**
|
||||
* Rules used to validate data in insert, update, and save methods.
|
||||
* The array must match the format of data passed to the Validation
|
||||
* library.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $validationRules = [];
|
||||
/**
|
||||
* Rules used to validate data in insert, update, and save methods.
|
||||
* The array must match the format of data passed to the Validation
|
||||
* library.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $validationRules = [];
|
||||
|
||||
/**
|
||||
* Contains any custom error messages to be
|
||||
* used during data validation.
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
protected $validationMessages = null;
|
||||
/**
|
||||
* Contains any custom error messages to be
|
||||
* used during data validation.
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
protected $validationMessages = null;
|
||||
|
||||
/**
|
||||
* Skip the model's validation. Used in conjunction with skipValidation()
|
||||
* to skip data validation for any future calls.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $skipValidation = false;
|
||||
/**
|
||||
* Skip the model's validation. Used in conjunction with skipValidation()
|
||||
* to skip data validation for any future calls.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $skipValidation = false;
|
||||
|
||||
/**
|
||||
* Our validator instance.
|
||||
*
|
||||
* @var \CodeIgniter\Validation\ValidationInterface
|
||||
*/
|
||||
protected $validation;
|
||||
/**
|
||||
* Our validator instance.
|
||||
*
|
||||
* @var \CodeIgniter\Validation\ValidationInterface
|
||||
*/
|
||||
protected $validation;
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
@ -253,11 +253,11 @@ class Model
|
||||
$this->tempReturnType = $this->returnType;
|
||||
$this->tempUseSoftDeletes = $this->useSoftDeletes;
|
||||
|
||||
if (is_null($validation))
|
||||
{
|
||||
$validation = \Config\Services::validation();
|
||||
}
|
||||
$this->validation = $validation;
|
||||
if (is_null($validation))
|
||||
{
|
||||
$validation = \Config\Services::validation();
|
||||
}
|
||||
$this->validation = $validation;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -286,13 +286,13 @@ class Model
|
||||
if (is_array($id))
|
||||
{
|
||||
$row = $builder->whereIn($this->primaryKey, $id)
|
||||
->get();
|
||||
->get();
|
||||
$row = $row->getResult($this->tempReturnType);
|
||||
}
|
||||
else
|
||||
{
|
||||
$row = $builder->where($this->primaryKey, $id)
|
||||
->get();
|
||||
->get();
|
||||
|
||||
$row = $row->getFirstRow($this->tempReturnType);
|
||||
}
|
||||
@ -323,7 +323,7 @@ class Model
|
||||
}
|
||||
|
||||
$rows = $builder->where($key, $value)
|
||||
->get();
|
||||
->get();
|
||||
|
||||
$rows = $rows->getResult($this->tempReturnType);
|
||||
|
||||
@ -354,7 +354,7 @@ class Model
|
||||
}
|
||||
|
||||
$row = $builder->limit($limit, $offset)
|
||||
->get();
|
||||
->get();
|
||||
|
||||
$row = $row->getResult($this->tempReturnType);
|
||||
|
||||
@ -389,7 +389,7 @@ class Model
|
||||
}
|
||||
|
||||
$row = $builder->limit(1, 0)
|
||||
->get();
|
||||
->get();
|
||||
|
||||
$row = $row->getFirstRow($this->tempReturnType);
|
||||
|
||||
@ -441,7 +441,7 @@ class Model
|
||||
// method, so simple base64 encoding will work for now.
|
||||
if (! is_numeric($id))
|
||||
{
|
||||
return '=_'.base64_encode($id);
|
||||
return '=_'.base64_encode($id);
|
||||
}
|
||||
|
||||
$id = (int)$id;
|
||||
@ -546,15 +546,15 @@ class Model
|
||||
*/
|
||||
public function save($data)
|
||||
{
|
||||
$saveData = $data;
|
||||
$saveData = $data;
|
||||
|
||||
// If $data is using a custom class with public or protected
|
||||
// properties representing the table elements, we need to grab
|
||||
// them as an array.
|
||||
if (is_object($data) && ! $data instanceof \stdClass)
|
||||
{
|
||||
$data = $this->classToArray($data);
|
||||
}
|
||||
// If $data is using a custom class with public or protected
|
||||
// properties representing the table elements, we need to grab
|
||||
// them as an array.
|
||||
if (is_object($data) && ! $data instanceof \stdClass)
|
||||
{
|
||||
$data = $this->classToArray($data);
|
||||
}
|
||||
|
||||
if (is_object($data) && isset($data->{$this->primaryKey}))
|
||||
{
|
||||
@ -564,53 +564,53 @@ class Model
|
||||
{
|
||||
$response = $this->update($data[$this->primaryKey], $data);
|
||||
}
|
||||
else
|
||||
{
|
||||
$response = $this->insert($data);
|
||||
}
|
||||
else
|
||||
{
|
||||
$response = $this->insert($data);
|
||||
}
|
||||
|
||||
// If it was an Entity class, check it for an onSave method.
|
||||
if (is_object($saveData) && ! $saveData instanceof \stdClass)
|
||||
{
|
||||
if (method_exists($saveData, 'onSave'))
|
||||
{
|
||||
$saveData->onSave();
|
||||
}
|
||||
}
|
||||
// If it was an Entity class, check it for an onSave method.
|
||||
if (is_object($saveData) && ! $saveData instanceof \stdClass)
|
||||
{
|
||||
if (method_exists($saveData, 'onSave'))
|
||||
{
|
||||
$saveData->onSave();
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
return $response;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Takes a class an returns an array of it's public and protected
|
||||
* properties as an array suitable for use in creates and updates.
|
||||
*
|
||||
* @param $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function classToArray($data): array
|
||||
{
|
||||
$mirror = new \ReflectionClass($data);
|
||||
$props = $mirror->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED);
|
||||
/**
|
||||
* Takes a class an returns an array of it's public and protected
|
||||
* properties as an array suitable for use in creates and updates.
|
||||
*
|
||||
* @param $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function classToArray($data): array
|
||||
{
|
||||
$mirror = new \ReflectionClass($data);
|
||||
$props = $mirror->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED);
|
||||
|
||||
$properties = [];
|
||||
$properties = [];
|
||||
|
||||
// Loop over each property,
|
||||
// saving the name/value in a new array we can return.
|
||||
foreach ($props as $prop)
|
||||
{
|
||||
// Must make protected values accessible.
|
||||
$prop->setAccessible(true);
|
||||
$properties[$prop->getName()] = $prop->getValue($data);
|
||||
}
|
||||
// Loop over each property,
|
||||
// saving the name/value in a new array we can return.
|
||||
foreach ($props as $prop)
|
||||
{
|
||||
// Must make protected values accessible.
|
||||
$prop->setAccessible(true);
|
||||
$properties[$prop->getName()] = $prop->getValue($data);
|
||||
}
|
||||
|
||||
return $properties;
|
||||
}
|
||||
return $properties;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Inserts data into the current table. If an object is provided,
|
||||
@ -622,30 +622,30 @@ class Model
|
||||
*/
|
||||
public function insert($data)
|
||||
{
|
||||
// If $data is using a custom class with public or protected
|
||||
// properties representing the table elements, we need to grab
|
||||
// them as an array.
|
||||
if (is_object($data) && ! $data instanceof \stdClass)
|
||||
{
|
||||
$data = $this->classToArray($data);
|
||||
}
|
||||
// If $data is using a custom class with public or protected
|
||||
// properties representing the table elements, we need to grab
|
||||
// them as an array.
|
||||
if (is_object($data) && ! $data instanceof \stdClass)
|
||||
{
|
||||
$data = $this->classToArray($data);
|
||||
}
|
||||
|
||||
// If it's still a stdClass, go ahead and convert to
|
||||
// an array so doProtectFields and other model methods
|
||||
// don't have to do special checks.
|
||||
if (is_object($data))
|
||||
{
|
||||
$data = (array)$data;
|
||||
}
|
||||
// If it's still a stdClass, go ahead and convert to
|
||||
// an array so doProtectFields and other model methods
|
||||
// don't have to do special checks.
|
||||
if (is_object($data))
|
||||
{
|
||||
$data = (array)$data;
|
||||
}
|
||||
|
||||
// Validate data before saving.
|
||||
if ($this->skipValidation === false)
|
||||
{
|
||||
if ($this->validate($data) === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Validate data before saving.
|
||||
if ($this->skipValidation === false)
|
||||
{
|
||||
if ($this->validate($data) === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Must be called first so we don't
|
||||
// strip out created_at values.
|
||||
@ -663,8 +663,8 @@ class Model
|
||||
|
||||
// Must use the set() method to ensure objects get converted to arrays
|
||||
$return = $this->builder()
|
||||
->set($data)
|
||||
->insert();
|
||||
->set($data)
|
||||
->insert();
|
||||
|
||||
if (! $return) return $return;
|
||||
|
||||
@ -684,30 +684,30 @@ class Model
|
||||
*/
|
||||
public function update($id, $data)
|
||||
{
|
||||
// If $data is using a custom class with public or protected
|
||||
// properties representing the table elements, we need to grab
|
||||
// them as an array.
|
||||
if (is_object($data) && ! $data instanceof \stdClass)
|
||||
{
|
||||
$data = $this->classToArray($data);
|
||||
}
|
||||
// If $data is using a custom class with public or protected
|
||||
// properties representing the table elements, we need to grab
|
||||
// them as an array.
|
||||
if (is_object($data) && ! $data instanceof \stdClass)
|
||||
{
|
||||
$data = $this->classToArray($data);
|
||||
}
|
||||
|
||||
// If it's still a stdClass, go ahead and convert to
|
||||
// an array so doProtectFields and other model methods
|
||||
// don't have to do special checks.
|
||||
if (is_object($data))
|
||||
{
|
||||
$data = (array)$data;
|
||||
}
|
||||
// If it's still a stdClass, go ahead and convert to
|
||||
// an array so doProtectFields and other model methods
|
||||
// don't have to do special checks.
|
||||
if (is_object($data))
|
||||
{
|
||||
$data = (array)$data;
|
||||
}
|
||||
|
||||
// Validate data before saving.
|
||||
if ($this->skipValidation === false)
|
||||
{
|
||||
if ($this->validate($data) === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Validate data before saving.
|
||||
if ($this->skipValidation === false)
|
||||
{
|
||||
if ($this->validate($data) === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Must be called first so we don't
|
||||
// strip out updated_at values.
|
||||
@ -725,9 +725,9 @@ class Model
|
||||
|
||||
// Must use the set() method to ensure objects get converted to arrays
|
||||
return $this->builder()
|
||||
->where($this->primaryKey, $id)
|
||||
->set($data)
|
||||
->update();
|
||||
->where($this->primaryKey, $id)
|
||||
->set($data)
|
||||
->update();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -747,13 +747,13 @@ class Model
|
||||
if ($this->useSoftDeletes && ! $purge)
|
||||
{
|
||||
return $this->builder()
|
||||
->where($this->primaryKey, $id)
|
||||
->update(['deleted' => 1]);
|
||||
->where($this->primaryKey, $id)
|
||||
->update(['deleted' => 1]);
|
||||
}
|
||||
|
||||
return $this->builder()
|
||||
->where($this->primaryKey, $id)
|
||||
->delete();
|
||||
->where($this->primaryKey, $id)
|
||||
->delete();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -780,13 +780,13 @@ class Model
|
||||
if ($this->useSoftDeletes && ! $purge)
|
||||
{
|
||||
return $this->builder()
|
||||
->where($key, $value)
|
||||
->update(['deleted' => 1]);
|
||||
->where($key, $value)
|
||||
->update(['deleted' => 1]);
|
||||
}
|
||||
|
||||
return $this->builder()
|
||||
->where($key, $value)
|
||||
->delete();
|
||||
->where($key, $value)
|
||||
->delete();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -806,8 +806,8 @@ class Model
|
||||
}
|
||||
|
||||
return $this->builder()
|
||||
->where('deleted', 1)
|
||||
->delete();
|
||||
->where('deleted', 1)
|
||||
->delete();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -840,7 +840,7 @@ class Model
|
||||
$this->tempUseSoftDeletes = false;
|
||||
|
||||
$this->builder()
|
||||
->where('deleted', 1);
|
||||
->where('deleted', 1);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -895,7 +895,7 @@ class Model
|
||||
public function chunk($size = 100, \Closure $userFunc)
|
||||
{
|
||||
$total = $this->builder()
|
||||
->countAllResults(false);
|
||||
->countAllResults(false);
|
||||
|
||||
$offset = 0;
|
||||
|
||||
@ -971,7 +971,7 @@ class Model
|
||||
*/
|
||||
public function protect(bool $protect = true)
|
||||
{
|
||||
$this->protectFields = $protect;
|
||||
$this->protectFields = $protect;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -1022,7 +1022,7 @@ class Model
|
||||
*/
|
||||
protected function doProtectFields($data)
|
||||
{
|
||||
if ($this->protectFields === false) return $data;
|
||||
if ($this->protectFields === false) return $data;
|
||||
|
||||
if (empty($this->allowedFields))
|
||||
{
|
||||
@ -1086,101 +1086,101 @@ class Model
|
||||
*/
|
||||
public function setTable(string $table)
|
||||
{
|
||||
$this->table = $table;
|
||||
$this->table = $table;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Grabs the last error(s) that occurred. If data was validated,
|
||||
* it will first check for errors there, otherwise will try to
|
||||
* grab the last error from the Database connection.
|
||||
*
|
||||
* @param bool $forceDB Always grab the db error, not validation
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function errors(bool $forceDB = false)
|
||||
{
|
||||
// Do we have validation errors?
|
||||
if ($forceDB === false && $this->skipValidation === false)
|
||||
{
|
||||
$errors = $this->validation->getErrors();
|
||||
/**
|
||||
* Grabs the last error(s) that occurred. If data was validated,
|
||||
* it will first check for errors there, otherwise will try to
|
||||
* grab the last error from the Database connection.
|
||||
*
|
||||
* @param bool $forceDB Always grab the db error, not validation
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function errors(bool $forceDB = false)
|
||||
{
|
||||
// Do we have validation errors?
|
||||
if ($forceDB === false && $this->skipValidation === false)
|
||||
{
|
||||
$errors = $this->validation->getErrors();
|
||||
|
||||
if (! empty($errors))
|
||||
{
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
if (! empty($errors))
|
||||
{
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
||||
// Still here? Grab the database-specific error, if any.
|
||||
$error = $this->db->getError();
|
||||
// Still here? Grab the database-specific error, if any.
|
||||
$error = $this->db->getError();
|
||||
|
||||
return $error['message'] ?? null;
|
||||
}
|
||||
return $error['message'] ?? null;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Validation
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
// Validation
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the value of the skipValidation flag.
|
||||
*
|
||||
* @param bool $skip
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function skipValidation(bool $skip = true)
|
||||
{
|
||||
$this->skipValidation = $skip;
|
||||
/**
|
||||
* Set the value of the skipValidation flag.
|
||||
*
|
||||
* @param bool $skip
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function skipValidation(bool $skip = true)
|
||||
{
|
||||
$this->skipValidation = $skip;
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Validate the data against the validation rules (or the validation group)
|
||||
* specified in the class property, $validationRules.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validate($data): bool
|
||||
{
|
||||
if ($this->skipValidation === true || empty($this->validationRules))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Validate the data against the validation rules (or the validation group)
|
||||
* specified in the class property, $validationRules.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validate($data): bool
|
||||
{
|
||||
if ($this->skipValidation === true || empty($this->validationRules))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Query Builder works with objects as well as arrays,
|
||||
// but validation requires array, so cast away.
|
||||
if (is_object($data))
|
||||
{
|
||||
$data = (array)$data;
|
||||
}
|
||||
// Query Builder works with objects as well as arrays,
|
||||
// but validation requires array, so cast away.
|
||||
if (is_object($data))
|
||||
{
|
||||
$data = (array)$data;
|
||||
}
|
||||
|
||||
// ValidationRules can be either a string, which is the group name,
|
||||
// or an array of rules.
|
||||
if (is_string($this->validationRules))
|
||||
{
|
||||
$valid = $this->validation->run($data, $this->validationRules);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->validation->setRules($this->validationRules, $this->validationMessages);
|
||||
$valid = $this->validation->run($data);
|
||||
}
|
||||
// ValidationRules can be either a string, which is the group name,
|
||||
// or an array of rules.
|
||||
if (is_string($this->validationRules))
|
||||
{
|
||||
$valid = $this->validation->run($data, $this->validationRules);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->validation->setRules($this->validationRules, $this->validationMessages);
|
||||
$valid = $this->validation->run($data);
|
||||
}
|
||||
|
||||
return (bool)$valid;
|
||||
}
|
||||
return (bool)$valid;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user