We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13385
    • 18 Posts
    I am working on a redesign of a site that lists inventory. The site was set up with TV’s to hold custom data, and a Maxigallery call is tied to each listing, which generally have 5 - 10 pictures). Originally, the site was designed to have all of the data manually entered, but now the amount of listings is reaching over 500 and manual upkeep is no longer practical. To streamline the upkeep of the site, I have written a script that takes all of the data about each item (from an XML file output by their sales quoting software), goes into the data base and updates each page based on the items stock numbers. The quoting program also has a data file associated with the XML that contains images of each item. The descriptions of each picture are in the XML file, as well as the relationships between each image file name and what stock number it belongs with. (Sorry for the long lead in.) Is there any possibility to make use of the maxigallery scripts to resize, thumb, update DB, and move images to the correct folders? Or, should I write my own programs to resize, thumb, move and update the maxigallery tables? Any and all advice, thoughts, or alternate suggestions will be very much appreciated!
      Jad ~ www.benchmark-creative.com
      • 7923
      • 4,213 Posts
      You’d need to do your own snippet that request maxigallery to do the stuff.. but there’s still no easy api for it..

      Basically what you could try is following:

      1. Make your snippet copy the image file to destination folder, eg. /assets/galleries/<docid>
      2. do a snippet that asks maxigallery to resynch the gallery, something like this (not tested):
      <?php
      // Path where the galleries are stored 
      $path_to_galleries="assets/galleries/"; // [ path ]
      
      // Path where MaxiGallery is installed
      define(MAXIGALLERY_PATH, "assets/snippets/maxigallery/");
      
      // Gallery id to resynch
      $manage_gallery = 89;
      
      // Set maxigallery to picture management mode
      $_REQUEST['mode'] = "admin";
      
      // Set action to resynch
      $_REQUEST['action'] = 'gallery_synch';
      
      //include snippet file
      $output = "";
      include($modx->config['base_path'].MAXIGALLERY_PATH.'maxigallery.php');
      ?>
      

      3. Create another snippet (or add to the snippet above) that updates the picture description and title to maxigallery db table via sql. If no-one else is uploading pictures at the same time, you can find the picture by looking max id value from the picture database.

      Note that this thing has to be run one by one for every picture that is uploaded from the xml. If you put more than one pic in the filesystem and then do resynch, maxigallery will upload all them an add to the db table.. so in that case, you must do logic to the script that updates the title so that it knows to update all files that were uploaded during resynch.


        "He can have a lollipop any time he wants to. That's what it means to be a programmer."
        • 13385
        • 18 Posts
        Doze,

        Thanks for the quick reply, and especially the example script. Hopefully I will be attempting some sort of implementation later tonight. Do you think that running your suggested solution inside of a loop that processes each picture, inside a loop that processes each item will be too much of a performance hit?

        To expand on your “note”. If I want to drop 10 pictures into a gallery (/assets/galleries/<docid>) and then resync, I need to make sure that my description/title adding script knows that I added 10 pictures and references the DB rows based on that. i.e. If 10 pictures, query script looks at max (id), then goes back 10 rows and starts adding the desc/title, working its way back to the most recent entry. All of that would be inside a loop that works its way through the individual items.

        My largest concern is that this whole process is going to be very slow. The picture files are likely to be over 25 megabytes. Your thoughts on which method would be most efficient will be much appreciated. Should I be looking at a totally different approach to this problem, or in your opinion is this a feasible approach?

        Thanks,
        -Jad
          Jad ~ www.benchmark-creative.com
          • 7923
          • 4,213 Posts
          Quote from: jad889nb at Feb 27, 2009, 05:26 PM

          Do you think that running your suggested solution inside of a loop that processes each picture, inside a loop that processes each item will be too much of a performance hit? 
          It’s not a performance hit, but the script takes some time to process, so be sure to set your server so that it doesn’t exceed the max running time of a script.

          Quote from: jad889nb at Feb 27, 2009, 05:26 PM

          To expand on your “note”.  If I want to drop 10 pictures into a gallery (/assets/galleries/<docid>) and then resync, I need to make sure that my description/title adding script knows that I added 10 pictures and references the DB rows based on that.  i.e. If 10 pictures, query script looks at max (id), then goes back 10 rows and starts adding the desc/title, working its way back to the most recent entry.  All of that would be inside a loop that works its way through the individual items. 
          Yes, that’s what I mean.. Or another option would be to find the picture from maxigallery database after resynch with the picture filename. MaxiGallery cleans the filenames using this, so if you are uploading images that and needs cleaning, you need to run the original image through same kind of logic (eg. [URL=http://mirror3.cvsdude.com/trac/doze/MaxiGallery/browser/trunk/assets/snippets/maxigallery/maxigallery.class.inc.php#L821]this) to know what the destination filename will be.. But maxigallery also adds a number to the end of the filename if file already exists in the gallery, so you need to take that into account also, if your picture filenames aren’t unique.. But if your files are with unique names and do not have any special characters, then maxigallery wont do anything with the filenames and you can easily use that to find the db row from maxigallery db table.

          Quote from: jad889nb at Feb 27, 2009, 05:26 PM

          My largest concern is that this whole process is going to be very slow.  The picture files are likely to be over 25 megabytes.   Your thoughts on which method would be most efficient will be much appreciated. Should I be looking at a totally different approach to this problem, or in your opinion is this a feasible approach?
          Well.. It doesn’t really matter if you do your script to run each picture in a loop one by one, or if you add more pictures to the galleries at the same time and update titles.. There will be some performance advantage, if you make it so that all pictures to be uploaded are added to the filesystem folder and then resynch and then update the title / descriptions.. But the main thing here is the very long running time of the script. Especially if you have large picture files, it takes a while for maxigallery to resize the thumbnails and so on.. so you need to have enough running time set for the php scripts in php configuration.. You need to do some testing that how long it will take to process.. The processing itself may possibly have some effect also to the server so that serving of pages during the process will be a littlebit slower, but I guess these kind of updates doesn’t happen very often so I wouldn’t think about it very much.. also it would be good to automate the process to do updating during night time etc. You could even automate it to take the site offline for the duration of the automated update, so clients accessing the site would get information that update is in progress..

          In any case, you need to just test and see how it’ll go..

          The best way in my opinion would be to create a script that handles just one picture at a time, then create an ajax updater page that will request one picture to be uploaded and wait for it’s completition, then request another one etc etc.. That way you would have to have the server maximum script processing time and memory limits to be enough for just to process one picture to the database. If you do the loop in php side, you need to have the max processing time and memory limits for the duration of uploading all pictures..

          So I would suggest to start with a script that updates one picture from the xml file to maxigallery and then after you have that working, think about adding ajax requester for it.. so ajax parses the xml file contents and asks php script one by one to add the files.


            "He can have a lollipop any time he wants to. That's what it means to be a programmer."