From eb86ae46c7cc60ae0f36ba386a020abebf0af345 Mon Sep 17 00:00:00 2001 From: nguyenanhung Date: Sun, 15 Sep 2024 03:51:53 +0700 Subject: [PATCH 1/2] Add function init_basic_codeigniter_storage_directory --- helpers/file_helper.php | 39 ++++++++++++++++++++++++++++++++++----- src/BaseHelper.php | 4 ++-- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/helpers/file_helper.php b/helpers/file_helper.php index fce0bac..4a786ff 100644 --- a/helpers/file_helper.php +++ b/helpers/file_helper.php @@ -120,7 +120,7 @@ function formatSizeUnits($bytes) return $bytes; } } -if ( ! function_exists('generateFileIndex')) { +if (!function_exists('generateFileIndex')) { /** * Function generateFileIndex * @@ -164,7 +164,7 @@ function generateFileIndex($file_path = '', $file_name = 'index.html') return false; } } -if ( ! function_exists('generateFileHtaccess')) { +if (!function_exists('generateFileHtaccess')) { /** * Function generateFileHtaccess * @@ -208,7 +208,7 @@ function generateFileHtaccess($file_path = '', $file_name = '.htaccess') return false; } } -if ( ! function_exists('generateFileReadme')) { +if (!function_exists('generateFileReadme')) { /** * Function genarateFileReadme * @@ -256,7 +256,7 @@ function generateFileReadme($file_path = '', $file_name = 'README.md') * Function makeNewFolder * * @param string $folderPath - * @param bool $gitkeep + * @param bool $gitkeep * * @return bool * @author : 713uk13m @@ -303,7 +303,7 @@ function makeNewFolder($folderPath = '', $gitkeep = false) * Function new_folder * * @param string $folder - * @param bool $gitkeep + * @param bool $gitkeep * * @return bool * @author : 713uk13m @@ -425,3 +425,32 @@ function getAllFileInFolder($path) } } } +if (!function_exists('init_basic_codeigniter_storage_directory')) { + function init_basic_codeigniter_storage_directory() + { + if (is_cli() && (defined('APPPATH') && defined('FCPATH'))) { + echo "Initialize storage directory" . PHP_EOL; + + makeNewFolder(APPPATH . 'cache'); + makeNewFolder(APPPATH . 'cache/ci_sessions'); + makeNewFolder(APPPATH . 'logs'); + makeNewFolder(APPPATH . 'logs-data'); + + makeNewFolder(FCPATH . 'storage'); + makeNewFolder(FCPATH . 'storage/cache'); + makeNewFolder(FCPATH . 'storage/cache_db'); + makeNewFolder(FCPATH . 'storage/cache_page'); + makeNewFolder(FCPATH . 'storage/ci_sessions'); + makeNewFolder(FCPATH . 'storage/cookies'); + makeNewFolder(FCPATH . 'storage/htmlPurity'); + makeNewFolder(FCPATH . 'storage/tmp'); + makeNewFolder(FCPATH . 'storage/logs'); + makeNewFolder(FCPATH . 'storage/logs/Requests'); + makeNewFolder(FCPATH . 'storage/logs-vendor'); + file_create(FCPATH . 'storage/logs/accessDenied.log'); + + echo "Storage directory initialized successfully" . PHP_EOL; + } + exit(); + } +} diff --git a/src/BaseHelper.php b/src/BaseHelper.php index 173335b..16221ce 100644 --- a/src/BaseHelper.php +++ b/src/BaseHelper.php @@ -19,8 +19,8 @@ */ class BaseHelper { - const VERSION = '1.6.5'; - const LAST_MODIFIED = '2024-09-08'; + const VERSION = '1.6.6'; + const LAST_MODIFIED = '2024-09-15'; const PROJECT_NAME = 'CodeIgniter - Basic Helper'; const AUTHOR_NAME = 'Hung Nguyen'; const AUTHOR_FULL_NAME = 'Hung Nguyen'; From 77aae98618b0f2970e35418551de7f51f4332448 Mon Sep 17 00:00:00 2001 From: nguyenanhung Date: Sun, 15 Sep 2024 03:54:03 +0700 Subject: [PATCH 2/2] Update init_basic_codeigniter_storage_directory --- helpers/file_helper.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/helpers/file_helper.php b/helpers/file_helper.php index 4a786ff..be29d3e 100644 --- a/helpers/file_helper.php +++ b/helpers/file_helper.php @@ -426,7 +426,7 @@ function getAllFileInFolder($path) } } if (!function_exists('init_basic_codeigniter_storage_directory')) { - function init_basic_codeigniter_storage_directory() + function init_basic_codeigniter_storage_directory($customizes = array()) { if (is_cli() && (defined('APPPATH') && defined('FCPATH'))) { echo "Initialize storage directory" . PHP_EOL; @@ -449,6 +449,12 @@ function init_basic_codeigniter_storage_directory() makeNewFolder(FCPATH . 'storage/logs-vendor'); file_create(FCPATH . 'storage/logs/accessDenied.log'); + if (!empty($customizes) && is_array($customizes)) { + foreach ($customizes as $folder) { + makeNewFolder($folder); + } + } + echo "Storage directory initialized successfully" . PHP_EOL; } exit();