5 * Copyright 2012, Alain Peyrat
6 * http://fusionforge.org/
8 * This file is part of FusionForge.
10 * FusionForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require_once dirname(__FILE__).'/../common/include/env.inc.php';
26 require_once $gfcommon.'include/pre.php';
27 require_once $gfcommon.'tracker/ArtifactStorage.class.php';
29 ini_set('memory_limit', -1);
30 ini_set('max_execution_time', 0);
32 $res = db_query_params('SELECT id FROM artifact_file WHERE bin_data !=$1', array(''));
34 echo 'UPGRADE ERROR: '.db_error();
38 $data = forge_get_config('data_path');
40 system("mkdir -p $data");
41 system("chown ".forge_get_config('apache_user').':'.forge_get_config('apache_group')." $data");
42 system("chmod 0700 $data");
45 $as = new ArtifactStorage();
46 $tmp = tempnam('/tmp', 'tracker');
48 while($row = db_fetch_array($res)) {
49 $res2 = db_query_params ('SELECT filesize, bin_data FROM artifact_file WHERE id=$1',
51 $row2 = db_fetch_array($res2);
52 $ret = file_put_contents($tmp, base64_decode($row2['bin_data']));
54 echo "UPGRADE ERROR: file_put_contents($tmp) error: returned false\n";
58 if ($ret != $row2['filesize']) {
59 echo "UPGRADE ERROR: file_put_contents($tmp): size error ($ret != ".$row2['filesize'].")\n";
63 $ret = $as->store($row['id'], $tmp);
65 echo "UPGRADE ERROR: $ret: ".$as->getErrorMessage()."\n";
73 db_query_params ('UPDATE artifact_file SET bin_data=$1', array(''));