2012-03-15 15:06:45 +01:00
< ? php
/**
* AppShell file
*
* PHP 5
*
* CakePHP ( tm ) : Rapid Development Framework ( http :// cakephp . org )
2012-06-08 17:00:07 +02:00
* Copyright 2005 - 2012 , Cake Software Foundation , Inc . ( http :// cakefoundation . org )
2012-03-15 15:06:45 +01:00
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice .
*
2012-06-08 17:00:07 +02:00
* @ copyright Copyright 2005 - 2012 , Cake Software Foundation , Inc . ( http :// cakefoundation . org )
2012-03-15 15:06:45 +01:00
* @ link http :// cakephp . org CakePHP ( tm ) Project
* @ since CakePHP ( tm ) v 2.0
* @ license MIT License ( http :// www . opensource . org / licenses / mit - license . php )
*/
2013-11-06 10:52:18 +01:00
App :: uses ( 'AppModel' , 'Model' );
2022-10-10 15:54:51 +02:00
App :: uses ( 'BackgroundJobsTool' , 'Tools' );
2024-04-17 15:08:38 +02:00
App :: uses ( 'BenchmarkTool' , 'Tools' );
2012-03-15 15:06:45 +01:00
2023-11-24 13:47:59 +01:00
require_once dirname ( __DIR__ ) . '/../Model/Attribute.php' ; // FIXME workaround bug where Vendor/symfony/polyfill-php80/Resources/stubs/Attribute.php is loaded instead
2012-03-15 15:06:45 +01:00
/**
* Application Shell
*
* Add your application - wide methods in the class below , your shells
* will inherit them .
*
* @ package app . Console . Command
*/
2022-10-10 15:54:51 +02:00
abstract class AppShell extends Shell
2021-09-03 08:48:44 +02:00
{
2022-10-10 15:54:51 +02:00
/** @var BackgroundJobsTool */
private $BackgroundJobsTool ;
2021-11-05 10:49:16 +01:00
public function initialize ()
2021-08-24 17:35:09 +02:00
{
2024-01-22 09:54:15 +01:00
$configLoad = $this -> Tasks -> load ( 'ConfigLoad' );
$configLoad -> execute ();
2024-04-17 15:08:38 +02:00
if ( Configure :: read ( 'Plugin.Benchmarking_enable' )) {
$Benchmark = new BenchmarkTool ( ClassRegistry :: init ( 'User' ));
$start_time = $Benchmark -> startBenchmark ();
register_shutdown_function ( function () use ( $start_time , $Benchmark ) {
$Benchmark -> stopBenchmark ([
'user' => 0 ,
'controller' => 'Shell::' . $this -> modelClass ,
'action' => $this -> command ,
'start_time' => $start_time
]);
});
}
2022-09-10 20:01:44 +02:00
parent :: initialize ();
2020-02-10 15:15:59 +01:00
}
2021-08-24 17:35:09 +02:00
2021-11-10 17:10:18 +01:00
public function perform ()
{
2021-11-11 10:45:21 +01:00
$this -> initialize ();
2021-11-10 17:10:18 +01:00
$this -> { array_shift ( $this -> args )}();
}
2021-08-24 17:35:09 +02:00
protected function _welcome ()
{
// disable welcome message
}
/**
* @ param mixed $data
* @ return string
* @ throws JsonException
*/
protected function json ( $data )
{
2022-10-24 10:56:41 +02:00
return JsonTool :: encode ( $data , true );
2021-08-24 17:35:09 +02:00
}
2021-09-30 15:13:34 +02:00
/**
* @ param mixed $value
* @ return bool
*/
protected function toBoolean ( $value )
{
$value = strtolower ( $value );
switch ( $value ) {
case 'true' :
case '1' :
return true ;
case 'false' :
case '0' :
return false ;
default :
$this -> error ( " Invalid state value ` $value `, it must be `true`, `false`, `1`, or `0`. " );
}
}
2022-10-10 15:54:51 +02:00
2024-01-12 11:57:02 +01:00
/**
* @ param string $newCommand
* @ return void
*/
protected function deprecated ( $newCommand )
{
2024-01-14 15:31:55 +01:00
$this -> err ( " <warning>Warning: This method is deprecated. Next time please use ` $newCommand `.</warning> " );
2024-01-12 11:57:02 +01:00
}
2022-10-10 15:54:51 +02:00
/**
* @ return BackgroundJobsTool
* @ throws Exception
*/
protected function getBackgroundJobsTool ()
{
if ( ! isset ( $this -> BackgroundJobsTool )) {
2022-11-06 18:25:48 +01:00
$settings = [ 'enabled' => false ];
if ( ! empty ( Configure :: read ( 'SimpleBackgroundJobs.enabled' ))) {
$settings = Configure :: read ( 'SimpleBackgroundJobs' );
}
$this -> BackgroundJobsTool = new BackgroundJobsTool ( $settings );
2022-10-10 15:54:51 +02:00
}
return $this -> BackgroundJobsTool ;
}
2012-03-15 15:06:45 +01:00
}