1#!/usr/bin/env php 2<?php 3/* 4 * Copyright (C) 2007-2016 Laurent Destailleur <eldy@users.sourceforge.net> 5 * Copyright (C) 2015 Jean Heimburger <http://tiaris.eu> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <https://www.gnu.org/licenses/>. 19 */ 20 21/** 22 * \file scripts/product/migrate_picture_path.php 23 * \ingroup scripts 24 * \brief Migrate pictures from old system prior to 3.7 to new path for 3.7+ 25 */ 26 27if (!defined('NOSESSION')) define('NOSESSION', '1'); 28 29$sapi_type = php_sapi_name(); 30$script_file = basename(__FILE__); 31$path = __DIR__.'/'; 32 33// Test if batch mode 34if (substr($sapi_type, 0, 3) == 'cgi') { 35 echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; 36 exit(-1); 37} 38 39@set_time_limit(0); // No timeout for this script 40define('EVEN_IF_ONLY_LOGIN_ALLOWED', 1); // Set this define to 0 if you want to lock your script when dolibarr setup is "locked to admin user only". 41 42// Include and load Dolibarr environment variables 43require_once $path."../../htdocs/master.inc.php"; 44require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php"; 45require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"; 46require_once DOL_DOCUMENT_ROOT."/core/lib/images.lib.php"; 47// After this $db, $mysoc, $langs, $conf and $hookmanager are defined (Opened $db handler to database will be closed at end of file). 48// $user is created but empty. 49 50// $langs->setDefaultLang('en_US'); // To change default language of $langs 51$langs->load("main"); // To load language file for default language 52 53// Global variables 54$version = DOL_VERSION; 55$error = 0; 56$forcecommit = 0; 57 58print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n"; 59dol_syslog($script_file." launched with arg ".join(',', $argv)); 60 61if (empty($argv[1])) { 62 print "Usage: $script_file subdirtoscan\n"; 63 print "Example: $script_file produit\n"; 64 exit(-1); 65} 66 67print '--- start'."\n"; 68 69$dir = DOL_DATA_ROOT; 70$subdir = $argv[1]; 71if (empty($dir) || empty($subdir)) { 72 dol_print_error('', 'dir not defined'); 73 exit(1); 74} 75if (!dol_is_dir($dir.'/'.$subdir)) { 76 print 'Directory '.$dir.'/'.$subdir.' not found.'."\n"; 77 exit(2); 78} 79 80$filearray = dol_dir_list($dir.'/'.$subdir, "directories", 0, '', 'temp$'); 81 82global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini; 83 84foreach ($filearray as $keyf => $valf) { 85 $ref = basename($valf['name']); 86 $filearrayimg = dol_dir_list($valf['fullname'], "files", 0, '(\.gif|\.png|\.jpg|\.jpeg|\.bmp)$', '(\.meta|_preview.*\.png)$'); 87 foreach ($filearrayimg as $keyi => $vali) { 88 print 'Process image for ref '.$ref.' : '.$vali['name']."\n"; 89 90 // Create small thumbs for image 91 // Used on logon for example 92 $imgThumbSmall = vignette($vali['fullname'], $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs"); 93 if (preg_match('/Error/', $imgThumbSmall)) 94 print $imgThumbSmall."\n"; 95 96 // Create mini thumbs for image (Ratio is near 16/9) 97 // Used on menu or for setup page for example 98 $imgThumbMini = vignette($vali['fullname'], $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs"); 99 if (preg_match('/Error/', $imgThumbMini)) 100 print $imgThumbMini."\n"; 101 } 102} 103 104$db->close(); // Close $db database opened handler 105 106exit($error); 107