utils
Table of Contents
Classes
- Packer
- The packer class is a PHP version of Dean Edwards's Js minifier and obfuscator originaly ported to PHP by Nicolas Martin and revised by us for php 8.4
Functions
- backup_instance() : string
- The backup instance utils create a backup of your HelPHP instance including the main db indicated in the db config (not the central one if it exist)
- beautify_module_list() : array<string|int, mixed>
- beautify_module_list is used during install or uninstall module to insert suppress module configuration into module list config in main.php file... it just do the job to keep is readable .
- check_replication() : string
- The check replica utils is checking is the master slave replication is still operationnal.
- make_constants_js() : string|files
- The constants utils is used to make/update a js file with all needed constants like some translations, basic context infos etc, anything that is necessary to make run js parts of modules and helPHP js libs
- create_module() : string
- create a basic module for helPHP
- make_install() : string
- create everything needed for installing a module
- create_object_sql_from_table() : string
- Create the json file describing a table in generated/sql_objects
- export_data_sql_to_json() : string
- Return a json describing all the entries in a table
- install_blocks() : string
- Install all blocks found in modules/block folder from helPHP framework
- install_module() : string
- Install a module in the instance and add a menu in admin hierarchy
- job_manager() : mixed
- here is our buddy the job manager, made to be run as a command an working with "jobs" database as a job pile.
- new_job() : void
- to add a new job in "jobs" database pile
- cancel_job() : void
- Cancel a job and move if from db to history
- set_status_job() : void
- Change the status of a job in the pile.
- get_job_progress() : string
- Get the progression of a job
- job_loop() : void
- The job loop will run until there is no more job to do, so it must be started at start or the server and it will go on infine loop waiting for job to execute.
- minify() : string|files
- Minify an instance : Take all js files to create only one js.gz file the same for the CSS theme.
- process_launcher() : mixed
- launch process in background and store their progress in redis, it's a subprocess script for helPHP\libs\utils\system_process_to_redis
- uninstall_module() : string
- Uninstall a module in the instance and
Functions
backup_instance()
The backup instance utils create a backup of your HelPHP instance including the main db indicated in the db config (not the central one if it exist)
backup_instance(mixed $target) : string
can be called from cli with instance path as argument: php helphp/utils/backup.php instance_home_path
Parameters
- $target : mixed
-
the home path
Return values
string —echoing results
beautify_module_list()
beautify_module_list is used during install or uninstall module to insert suppress module configuration into module list config in main.php file... it just do the job to keep is readable .
beautify_module_list(mixed|array<string|int, mixed> $module_list, mixed|array<string|int, mixed> $temporary_module) : array<string|int, mixed>
And if you're asking what is $temporary_module ? It's a surprise ;) job in progress..
Parameters
- $module_list : mixed|array<string|int, mixed>
- $temporary_module : mixed|array<string|int, mixed>
Return values
array<string|int, mixed> —the module list beautified
check_replication()
The check replica utils is checking is the master slave replication is still operationnal.
check_replication(mixed $target) : string
the user used for connection must have "SUPER" or "SLAVE MONITOR" privilege can be called from cli with instance path as argument: php helphp/utils/check_replica.php instance_home_path
Parameters
- $target : mixed
-
the home path of the instance to get db config
Return values
string —echoing results
make_constants_js()
The constants utils is used to make/update a js file with all needed constants like some translations, basic context infos etc, anything that is necessary to make run js parts of modules and helPHP js libs
make_constants_js(mixed $target) : string|files
can be called from cli with instance path as argument: php helphp/utils/constants.php instance_home_path
Parameters
- $target : mixed
-
the home path of the instance to get config
Return values
string|files —echoing results and js/constants*.js files in the instance.
create_module()
create a basic module for helPHP
create_module(string $module_name) : string
To call from CLI php create_module.php module_name
Parameters
- $module_name : string
-
name of the module
Return values
string —error or success message
make_install()
create everything needed for installing a module
make_install(string $module_name, string $object_list[, bool $sql_only = false ][, mixed $public = true ]) : string
Will create the file install.php with sql query and list of file needed inside. Will also create both index.php for admin and public
To call from CLI php create_module_installer.php module_name sql_object1,sql_object2,... true|false if the module has no db php create_module_installer.php module_name no_db
Parameters
- $module_name : string
-
name of the module
- $object_list : string
-
sql object of the module name separated by a ','
- $sql_only : bool = false
-
Optional. True, only create the sql part, ignore file
- $public : mixed = true
Return values
string —error or success message
create_object_sql_from_table()
Create the json file describing a table in generated/sql_objects
create_object_sql_from_table(string $instance_path, string $table_name[, mixed $CLI = false ]) : string
To call from CLI php create_object_sql_from_table.php instance_path table_name
Parameters
- $instance_path : string
-
path to the instance
- $table_name : string
-
table's name
- $CLI : mixed = false
Return values
string —error or success message
export_data_sql_to_json()
Return a json describing all the entries in a table
export_data_sql_to_json(string $instance_path, string $table_name) : string
To call from CLI php export_data_sql_to_json.php instance_path table_name
Parameters
- $instance_path : string
-
path to the instance
- $table_name : string
-
table's name
Return values
string —JSON
install_blocks()
Install all blocks found in modules/block folder from helPHP framework
install_blocks(mixed $instance_path) : string
To call from CLI : php install_blocks.php /path/to/my/instance/
Parameters
- $instance_path : mixed
Return values
string —error or success message
install_module()
Install a module in the instance and add a menu in admin hierarchy
install_module(mixed $instance_path, mixed $module_name[, bool $ignore_file_and_folder = false ]) : string
To call from CLI : php install_module.php /path/to/my/instance/ module_name
Parameters
- $instance_path : mixed
- $module_name : mixed
- $ignore_file_and_folder : bool = false
Return values
string —error or success message
job_manager()
here is our buddy the job manager, made to be run as a command an working with "jobs" database as a job pile.
job_manager(mixed $argv) : mixed
arguments : -k , to identify the job -C , callback when command is done -c , the command to execute -f , path to the instance -a , action for the job manager (new, progress or cancel)
exemples :
-
add a job : $job_manager_call='php /home/helphp/utils/job_manager.php -a"new" -f"'.$from.'" -c"'.$cmd.'" -C"'.$callback.'" -k"'.$key.'"';
-
get progress : $job_manager_call='php /home/helphp/utils/job_manager.php -a"progress" -f"'.$from.'" -k"'.$key.'"';
-
cancel : $job_manager_call='php /home/helphp/utils/job_manager.php -a"cancel" -f"'.$from.'" -k"'.$key.'"';
must be followed by : exec($job_manager_call);
Parameters
- $argv : mixed
new_job()
to add a new job in "jobs" database pile
new_job(mixed $from, mixed $command, mixed $callback, mixed $key) : void
Parameters
- $from : mixed
-
origine identifier
- $command : mixed
-
to exec
- $callback : mixed
-
ta call back after exec
- $key : mixed
-
the key identifier that permit to follow th process.
cancel_job()
Cancel a job and move if from db to history
cancel_job(mixed $from, mixed $key) : void
Parameters
- $from : mixed
-
origine identifier
- $key : mixed
-
indentifier of the job to cancel.
set_status_job()
Change the status of a job in the pile.
set_status_job(mixed $from, mixed $key, mixed $status) : void
Parameters
- $from : mixed
-
origine identifier
- $key : mixed
-
indentifier of the job
- $status : mixed
-
possible values :
- 0 undone
- 1 in progress
- 2 done
- 3 error
get_job_progress()
Get the progression of a job
get_job_progress(mixed $from, mixed $key) : string
Parameters
- $from : mixed
-
origine identifier
- $key : mixed
-
indentifier of the job
Return values
string —messages / echo from the process if it got status = 1 (1 in progress)
- status 0 : it will return "wait"
- status 2 : "ok!" because finished
- status 3 : "err" an error happenned.
job_loop()
The job loop will run until there is no more job to do, so it must be started at start or the server and it will go on infine loop waiting for job to execute.
job_loop() : void
minify()
Minify an instance : Take all js files to create only one js.gz file the same for the CSS theme.
minify(string $target) : string|files
At the end you'll get only two small files instead of 30/40~ and with a size reduced by ten. of course the impact on speed is huge and as the number or http queries is reduced the server ressource are increased by 20 ~ !
After minifying, you just need to swith DEVMODE to false in your main config file to see the difference.
it's common practices to keep one version of the instance as a dev version and the second as production.
in that case you just need to move css/gz/* and jsgz/* files from dev version to prod + database
Parameters
- $target : string
-
the home path of the instance to get config
Return values
string|files —echoing results of minification.
process_launcher()
launch process in background and store their progress in redis, it's a subprocess script for helPHP\libs\utils\system_process_to_redis
process_launcher(array<string|int, mixed> $argv) : mixed
must be launch from cli with arguments
can be used also to "force cancel" a job when type of process is "job", it's a special case when we want to create easily some "cancel" button for job in progress
Parameters
- $argv : array<string|int, mixed>
-
the arguments of the cli command : argument Options: -k , the key to identify the process in redis -t , the type of the process -a , params depending the type -l , list of files that need to be locked during the process -i , path to the instance
Tags
uninstall_module()
Uninstall a module in the instance and
uninstall_module(mixed $instance_path, mixed $module_name[, bool $ignore_file_and_folder = false ][, mixed $CLI = false ]) : string
To call from CLI : php uninstall_module.php /path/to/my/instance/ module_name
Parameters
- $instance_path : mixed
- $module_name : mixed
- $ignore_file_and_folder : bool = false
- $CLI : mixed = false
Return values
string —error or success message