/**
  * generateZip
  * 
  * @param AutoZipConfig $autozip
  * @param string $version_number
  */
 public static function generateZip(AutoZipConfig $autozip, $version_number = null)
 {
     // Move the configured folder as source folder
     if ($autozip->source_folder) {
         self::cliExec('mv download/' . $autozip->source_folder . ' source');
     } else {
         self::cliExec('mv download source');
     }
     // Zip with or without root folder in the zip
     if ($autozip->zip_folder) {
         self::cliExec('mv source ' . $autozip->zip_folder);
         self::cliExec('zip -qr autozip.zip ' . $autozip->zip_folder);
     } else {
         self::cliExec('zip -qr ../autozip.zip . ', array(), _AUTOZIP_TMP_ . 'source');
     }
     if ($autozip->id_attachment) {
         // get the Attachement config
         $attachment = new Attachment($autozip->id_attachment);
         if (!$attachment->file) {
             throw new PrestaShopException('The Attachement does not exists. Please update the autozip association');
         }
         // Move the generated zip as the "regular" Attachement
         self::cliExec('mv autozip.zip ' . _PS_DOWNLOAD_DIR_ . $attachment->file);
         if ($autozip->zip_basename) {
             $attachment->file_name = $autozip->zip_basename . ($version_number ? '-' . $version_number : '') . '.zip';
         }
         $attachment->mime = 'application/zip';
         $attachment->update();
     } else {
         if ($autozip->id_product_download) {
             // get the Product Download config
             $product_download = new ProductDownload($autozip->id_product_download);
             if (!$product_download->id_product) {
                 throw new PrestaShopException('The product Download does not exists. Please update the autozip association');
             }
             // Move the generated zip as the "regular" Product Download
             self::cliExec('mv autozip.zip ' . _PS_DOWNLOAD_DIR_ . $product_download->filename);
             if ($autozip->zip_basename) {
                 $product_download->display_filename = $autozip->zip_basename . ($version_number ? '-' . $version_number : '') . '.zip';
             }
             $product_download->date_add = date('Y-m-d H:i:s');
             //Prestashop dos not like the way he is himself storing an empty date (we do not change this field)
             if ($product_download->date_expiration === '0000-00-00 00:00:00') {
                 $product_download->date_expiration = null;
             }
             $product_download->update();
         }
     }
 }