1084

list_all_modules

Comments for “list_all_modules”
 

Posted by Dom on Monday 15th April 2024 at 17:59 GMT

One for Dafa methinks

In the list_all_modules we have the following (with an element of amendment by myself).

// Check if the assets directory exists
                    if (is_dir($assets_dir)) {
                        // Check if the module has an API defined by looking for an api.json file in the assets directory
                        $api_json_exists = file_exists($assets_dir . '/api.json');
                    } else {
                        $api_json_exists = false;
                    }

                    // Construct a check to see if there is a module_pics and module_pics_thumbnails folder
                    // in the assets folder.  That would indicate that there's a single picture uploader in the module.
                    $picsDir = $assets_dir .'/'.$module_name.'_pics';
                    $pic_directory_exists = is_dir($picsDir) ? true : false;
                    $pic_directory =  $picsDir;
                    // Initialize an array to store information about submodules
                    $submodules = [];


on my machine $picsDir evaluates to C:/xampp/htdocs/datagen/modules\orders/assets/orders_pics

Where is the backslash after modules coming from? Is it by chance the use of getPathname() which is used in the determination of the $assets_dir variable?

With any luck I'll figure this out but then again I might not!
Level One Member

Dom

User Level: Level One Member

Date Joined: 12/01/2024

Posted by DaFa on Tuesday 16th April 2024 at 03:13 GMT

Hi Dom,
Path separators on Windows are a bit confusing as backslashes are what the system uses by default but forward slashes still work too.
I suspect that the backslash is coming from
foreach (new DirectoryIterator($modules_dir) as $module_dir) {
Nevertheless, you could just ignore it as it should still work, or you could just do a string replace
$assets_dir = str_replace('\\', '/', $assets_dir);
or if you want to keep to the Windows systems default folder separator, check if it's a backslash:
// Check if operating system is Windows
if (PHP_OS_FAMILY === 'Windows') {
    // Replace forward slashes with backslashes
    $assets_dir = str_replace('/', '\\', $assets_dir);
} else {
    // Replace backslashes with forward slashes
    $assets_dir = str_replace('\\', '/', $assets_dir);
}

This comment was edited by DaFa on Tuesday 16th April 2024 at 07:11 GMT

Founding Member

DaFa

User Level: Founding Member

Date Joined: 30/11/2018

Posted by Dom on Tuesday 16th April 2024 at 07:15 GMT

Thank you Simon

That makes perfect sense.
Level One Member

Dom

User Level: Level One Member

Date Joined: 12/01/2024

×