JoomGalleryfriends / JG4-dev

Development repository for JoomGallery v4.x
GNU General Public License v3.0
10 stars 7 forks source link

FileManager service #26

Closed Elfangor93 closed 2 years ago

Elfangor93 commented 2 years ago

What is this service for

The FileManager service will be used to handle the files and folders created in the filesystem. I offers methods to perform processes (create, delete, check, move) on image files and folders. The file structure is created based on...

How to use this service

You can load the service anywhere in Joomla by doing

$component = Factory::getApplication()->bootComponent('com_joomgallery');  // boot JoomGallery component
$component->createFileManager();   // instantiate service
$file_manager = $component->getFileManager();   // load the service into your scope
$file_manager ->createImages('image.jpg', 'new_filename.jpg', 1);  // create image files in category with id=1
$file_manager ->deleteImages(22);   // delete image files with image id=22

How to test this service

Make sure "Debug System" is "Yes" in Joomla Global configuration. Open the file /administrator/com_joomgallery/src/View/Faulties/HtmlView.php and insert the following code on line 62 after throw new \Exception(implode("\n", $errors)); }

    // Test FileManager
    $this->component->createConfig();
    $this->component->createFileManager();
    $manager = $this->component->getFileManager();
    $src     = \Joomla\CMS\Filesystem\Path::clean(JPATH_ROOT.'/images/<YOUR_IMAGE.jpg>');
    $settings = array(  'filename'       => '<YOUR_FILENAME.jpg>',
                        'imgid'          => <IMGID>,
                        'catid'          => <CATID>,
                        'parent_catid'   => <PARENT_CATID>,
                        'cat_alias'      => '<YOUR_CATEGORY>');

    // Create Category
    //$manager->createCategory($settings['cat_alias'], $settings['parent_catid']);

    // Create Image
    // $manager->createImages($src, $settings['filename'], $settings['catid']);

    // Check Image
    // $img_info = $manager->checkImages($settings['filename']);
    // dump($img_info);

    // Get Imagetype path of existing image
    // $img_path = $manager->getImgPath('original', $settings['imgid']);
    // dump($img_path);

    // Copy Image
    // $manager->copyImages($settings['filename'], 5);

    // Move Image
    // $manager->moveImages($settings['filename'], 5);

    // Check Category
    // $cat_info = $manager->checkCategory($settings['cat_alias']);
    // dump($cat_info);

    // Get Category path of existing image
    // $cat_path = $manager->getCatPath('original', $settings['catid']);
    // dump($cat_path);

    // Move Category
    // $manager->moveCategory($settings['catid'], 5);

    // Copy Category
    // $manager->copyCategory($settings['catid'], 5);

    // Delete Category
    // $manager->deleteCategory($settings['cat_alias']);

    // Delete Image
    // $manager->deleteImages($settings['filename']);

Create a category using the category manager and give it the alias=. You can nest this category as you like below any other category already created. Note the id of the direct parent category of the new created category ().

Category Manager: grafik


Create an image using the image manager. Select the category you just created (). Go into the database and edit your just created image record in the table #__joomgallery. In the row 'filename' write the filename as which you want the created files to be stored ().

Image Manager: grafik

Database (#__joomgallery) grafik

Navigate to Components->JoomGallery->Maintenance Manager to see the FileManager service running...

What to test

Different configuration settings

General Settings >> Image Processing >> Image processing (static images)

Different source images and destination categories

The service will create a folder structure and images in such a way as you defined it in your image entry and your category entries in the database (including nesting).

Different processing methods

Test the different methods from the service Available methods:

more infos: FileManager interface

szepty-ziemi commented 2 years ago

@Elfangor93 I created category without any issues. But when tried to create new image I get error right after I click 'New' in Image Manager:

obraz

ENV

obraz

I reverted changes in /administrator/com_joomgallery/src/View/Faulties/HtmlView.php but no changes and error persist.

Elfangor93 commented 2 years ago

@szepty-ziemi : Yes, I know that. This issue will be fixed in the next PR. It is not ment to work in this PR.

szepty-ziemi commented 2 years ago

Yes, I know that. This issue will be fixed in the next PR. It is not ment to work in this PR.

@Elfangor93 Okay, but one of the testing steps is Create an image using the image manager. so this issue seems to be a blocker.

Elfangor93 commented 2 years ago

Sorry @szepty-ziemi for my confusion. This bug you mention with the image creation should be fixed with commit b052477. Please make shure, that you are using the latest version of this PR. I forgot, that I fixed that... ;-)

szepty-ziemi commented 2 years ago

@Elfangor93 I downloaded package once again. Removed previous installation and installed from fresh package. Issue persist:

obraz

I checked if your changes are available in ROOT/administrator/com_joomgallery/src/Model/ImageModel.php and they are:

obraz

Nevertheless error is still present. I've tried on Linux but outcome is the same.

Could you take a second look?

Elfangor93 commented 2 years ago

Yes, you are right @szepty-ziemi, there was a bug. Should be fixed now...

szepty-ziemi commented 2 years ago

@Elfangor93 thank you, I confirm that it works. But noticed another issue:

GIVEN User has already successfully created and image WHEN Clicking on image name to edit image THEN Error appears BUT User should be able to enter image editing mode

obraz

ENV: https://prnt.sc/vZjYcGgpiOCX

This is not a blocker so I will proceed with further testing.

Elfangor93 commented 2 years ago

The issues in the image manager will be fixed with the next PR. This is ment to finish the FileManager service not the image manager GUI.

szepty-ziemi commented 2 years ago

I followed testing guide:

  1. Copied the code:

obraz

  1. Created structure

obraz

obraz

obraz

obraz

So trying to process 'image-1' that sits in 'category-1' file is here (published was 0 but I changed it to 1 with the same result):

obraz

When moving to Components->JoomGallery->Maintenance Manager, nothing happens. No folders are created no info is displayed.

@Elfangor93 Am I doing something wrong? Or misunderstood the instructions?

Elfangor93 commented 2 years ago

The code you copied is just a template. In order to perform something you have to uncomment the line you want to perform.

Elfangor93 commented 2 years ago

And take care that line 66 and 67 are adjusted according to your image and category structure you created.

Elfangor93 commented 2 years ago

If you try to process image-1 you need to adjust the filename row of your record in the database according to your settings in the code including file extension (image-1-filename.jpg)

Elfangor93 commented 2 years ago

The settings for the category-1 seems correct.

Elfangor93 commented 2 years ago

If you correctly set up database (category and image) and code, you can uncomment for example line 73 to create the folders for your category-1.

So uncomment the line and refresh the page in the maintenance manager and you should see a message and the folders /images created in the file explorer.

szepty-ziemi commented 2 years ago

@Elfangor93 thank you for explanation. I was able to confirm:

Could you explain how to use:

As they are not in the template and I can't figure out how to use them properly.

szepty-ziemi commented 2 years ago

When testing:

I encountered on an issue. I've created new image type "fix"

obraz

Then run this method:

obraz

And this was displayed:

obraz

obraz

obraz

Structure was correctly created:

obraz

But image itself become... well... strange:

obraz

Original is:

obraz

Please, advise.

MrMusic commented 2 years ago

I encountered on an issue. I've created new image type "fix"

@szepty-ziemi Yes, I agree with you. I think the use of 'new' image types is generally problematic: If there are already images exists and then new image types are added in the configuration or changes are made to the existing image types, this does not affect the existing images but only future ones. Presumably this will often lead to confusion. I see the implementation of 'any' number of new image types as quite difficult, also with regard to the later use in the frontend. My recommendation would be to start only with the three known image types (original, detail, thumbnail) and to implement the feature with the additional image types in a later version (JoomGallery 4.1?). This would perhaps speed up the development of JoomGallery 4.0 and makes it easier to test the current version.

szepty-ziemi commented 2 years ago

@Elfangor93 yes, I agree. Let's stay with know 3 image types and return to this feature later.

Elfangor93 commented 2 years ago

@MrMusic, @szepty-ziemi What about removing the add button in the GUI in the Configuration Manager >> General Settings >> Image Processing >> Image processing (static images) but leaving all the functionality in the code such that we can activate and test additional image types in a later version very easily? I really want to have the possibility to create multiple image types in the future.

grafik

szepty-ziemi commented 2 years ago

@Elfangor93 I agree, this will be the easiest way

Elfangor93 commented 2 years ago

When testing:

* Different configuration settings

I encountered on an issue. I've created new image type "fix"

...

Please, advise.

Thanks @szepty-ziemi I was able to reproduce this issue. It happens when you create a new imagetype by just entering the image type name and save the configuration. If you would open the configuration and save it again the issue disappears.

Elfangor93 commented 2 years ago

I fixed the issue. @szepty-ziemi please confirm that the issue with the new imagetype "fix" is fixed now.

Elfangor93 commented 2 years ago

I also updated the testing template code in order for you to test the two methods "getImgPath" and "getCatPath".

MrMusic commented 2 years ago

@MrMusic, @szepty-ziemi What about removing the add button in the GUI in the Configuration Manager >> General Settings >> Image Processing >> Image processing (static images) but leaving all the functionality in the code such that we can activate and test additional image types in a later version very easily? I really want to have the possibility to create multiple image types in the future.

Yes, I agree too.

Elfangor93 commented 2 years ago

Since this PR is only about the service and not about the GUI, I will hide the Button in the next PR (#31).

Elfangor93 commented 2 years ago

@szepty-ziemi Can we merge this PR?

szepty-ziemi commented 2 years ago

@Elfangor93 I will check everything after your fixes today. Will let you know ;)

szepty-ziemi commented 2 years ago

ENV: https://prnt.sc/f-4vpeI2yH8p (this time tested on Linux)

When using this method:

obraz

I get an error:

obraz

All necessary input is provided correctly and works with previous methods. Please, advise.

szepty-ziemi commented 2 years ago

ENV as above. Category structure: https://prnt.sc/D87R_2vkSISv DB: https://prnt.sc/Ht8L4FV2IWKf

I'm checking "Get Category path of existing image"

obraz

As far I understand it should be:

home/siristru/public_html/j4/images/joomgallery/originals/category-1/second-category/category-z

But I get:

obraz

And this is site root only.

szepty-ziemi commented 2 years ago

@Elfangor93 I confirm that issue reported here https://github.com/JoomGalleryfriends/JG4-dev/pull/26#issuecomment-1199900494 was fixed 👍

I spotted no other issues. All seems to work correctly on Linux server... except those two issues reported above.