18 define(
'FUDGE_FV_OK', 1);
19 define(
'FUDGE_FV_ERROR', 2);
20 define(
'FUDGE_FV_NOT_CHECKED_OUT', 4);
21 define(
'FUDGE_FV_MODIFIED', 8);
22 define(
'FUDGE_FV_NOT_MODIFIED', 16);
23 define(
'FUDGE_FV_CURRENT_VERSION', 32);
24 define(
'FUDGE_FV_OLD_VERSION', 64);
51 var $num_lock_attempts = 4;
63 if (file_exists($dir.
'/.FFV/error.log')) {
64 trigger_localised_error(
'FVER0024', E_USER_ERROR, $dir);
81 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
82 require_once SQ_LIB_PATH.
'/db_install/db_install.inc';
84 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
85 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
87 $dir = SQ_DATA_PATH.
'/file_repository';
89 if (!create_directory($dir)) {
90 trigger_localised_error(
'FVER0022', E_USER_WARNING, $dir);
91 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
92 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
96 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
97 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
114 return iso8601_ts($iso8601);
130 return ts_iso8601($timestamp);
149 $sql =
'SELECT f.fileid, f.path, f.filename,
150 h.version, h.from_date, h.to_date, h.file_size, h.md5, h.sha1, h.removal, h.extra_info
151 FROM sq_file_vers_file f INNER JOIN sq_file_vers_history h ON f.fileid = h.fileid
152 WHERE f.fileid = :fileid
153 AND '.((is_null($version)) ?
'to_date IS NULL' :
'version = :version');
158 if (!is_null($version)) {
162 if (!empty($result)) {
163 $result = $result[0];
165 }
catch (Exception $e) {
166 throw new Exception(
'Unable to get versioning information for file ID '.$fileid.
' at version '.(is_null($version) ?
'(current)' : $version).
' due to database error: '.$e->getMessage());
169 if (!empty($result)) {
170 $result[
'fileid'] = (int) $result[
'fileid'];
171 $result[
'version'] = (int) $result[
'version'];
172 $result[
'from_date'] = iso8601_ts($result[
'from_date']);
173 if (!empty($result[
'to_date'])) {
174 $result[
'to_date'] = iso8601_ts($result[
'to_date']);
176 $result[
'file_size'] = (int) $result[
'file_size'];
196 $ffv_dir = dirname($real_file).
'/.FFV';
197 if (!is_dir($ffv_dir))
return FUDGE_FV_NOT_CHECKED_OUT;
199 $ffv_file = $ffv_dir.
'/'.basename($real_file);
200 if (!is_file($ffv_file)) {
201 return FUDGE_FV_NOT_CHECKED_OUT;
204 $ffv = parse_ini_file($ffv_file);
205 if (!is_array($ffv)) {
206 trigger_localised_error(
'FVER0025', E_USER_WARNING);
207 return FUDGE_FV_ERROR;
210 if ($this->_dir != $ffv[
'dir']) {
211 trigger_localised_error(
'FVER0008', E_USER_WARNING);
212 return FUDGE_FV_ERROR;
217 trigger_localised_error(
'FVER0028', E_USER_WARNING, $ffv[
'version'], $ffv[
'fileid']);
218 return FUDGE_FV_ERROR;
221 $rep_file = $this->_dir.
'/'.$info[
'path'].
'/'.$info[
'filename'];
223 if (empty($info[
'removal'])) {
225 trigger_localised_error(
'FVER0027', E_USER_NOTICE, $info[
'path'], $info[
'filename'], $info[
'version']);
226 return FUDGE_FV_ERROR;
250 $sql =
'SELECT fileid
251 FROM sq_file_vers_file
253 AND filename = :filename';
260 }
catch (Exception $e) {
261 throw new Exception(
'Unable to get file versioning information for file "'.hide_system_root($file_path).
'" due to database error: '.$e->getMessage());
264 if (empty($fileid))
return Array();
280 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
281 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
284 $select =
'SELECT COUNT(*)
285 FROM sq_file_vers_lock
286 WHERE fileid = :fileid';
287 $insert =
'INSERT INTO sq_file_vers_lock (fileid) VALUES (:fileid)';
294 }
catch (Exception $e) {
295 throw new Exception(
'Unable to prepare file versioning locking queries for file ID "'.$fileid.
'" due to database error: '.$e->getMessage());
300 for ($i = 0; $i < $this->num_lock_attempts; $i++) {
304 }
catch (Exception $e) {
305 throw new Exception(
'Unable to select file versioning locking information for file ID "'.$fileid.
'" due to database error: '.$e->getMessage());
308 if (empty($result)) {
314 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
315 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
317 }
catch (Exception $e) {
324 if ($i < $this->num_lock_attempts - 1) sleep(1);
328 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
329 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
346 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
347 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
350 $sql =
'DELETE FROM sq_file_vers_lock
351 WHERE fileid = :fileid';
356 }
catch (Exception $e) {
357 throw new Exception(
'Unable to unlock file ID "'.$fileid.
'" due to database error: '.$e->getMessage());
360 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
361 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
378 function add($rep_path, $real_file, $extra_info=
'')
382 if (!is_file($real_file) || !is_readable($real_file)) {
383 trigger_localised_error(
'FVER0003', E_USER_NOTICE, $real_file);
387 $filename = basename($real_file);
392 if ($existing_ffv_info != FUDGE_FV_NOT_CHECKED_OUT && empty($existing_ffv_info[
'removal'])) {
393 trigger_localised_error(
'FVER0017', E_USER_NOTICE, $real_file);
398 $rep_path = preg_replace(
'/\/+$/',
'', $rep_path);
399 $rep_file = $rep_path.
'/'.basename($real_file);
402 $bits = explode(
'/', $rep_file);
403 foreach ($bits as $bit) {
405 if (strtoupper($bit) ==
'.FFV') {
406 trigger_localised_error(
'FVER0015', E_USER_NOTICE, $real_file, $rep_path);
410 if (preg_match(
'/,FFV[0-9]+$/i', $bit)) {
411 trigger_localised_error(
'FVER0016', E_USER_NOTICE, $real_file, $rep_path);
419 if (!empty($current_info) && empty($current_info[
'removal'])) {
420 trigger_localised_error(
'FVER0004', E_USER_WARNING, $rep_file);
424 }
else if (empty($current_info)) {
429 $concat_1 =
'(path || \'/\' || filename)';
430 $concat_2 =
'(path || \'/\' || filename || \'%\')';
431 $sql =
'SELECT COUNT(*)
432 FROM sq_file_vers_file
433 WHERE '.$concat_1.
' LIKE :path_wildcard
434 OR :path LIKE '.$concat_2;
441 }
catch (Exception $e) {
442 throw new Exception(
'Unable to get file versioning information for file "'.hide_system_root($file_path).
'" due to database error: '.$e->getMessage());
445 if (!empty($result)) {
446 trigger_localised_error(
'FVER0014', E_USER_NOTICE, $real_file, $rep_path);
452 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
453 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
457 if (empty($current_info)) {
459 $fileid = (int) $fileid;
461 $sql =
'INSERT INTO sq_file_vers_file (fileid, path, filename)
462 VALUES (:fileid, :path, :filename)';
470 }
catch (Exception $e) {
471 throw new Exception(
'Unable to insert new file versioning information for file "'.$filename.
'" due to database error: '.$e->getMessage());
476 $fileid = (int) $current_info[
'fileid'];
482 trigger_localised_error(
'FVER0018', E_USER_NOTICE);
483 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
484 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
489 $version = $this->
_updateFile($fileid, $rep_path, $real_file, $extra_info);
490 if (empty($version)) {
492 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
493 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
499 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
500 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
519 function _updateFile($fileid, $rep_path, $real_file, $extra_info=
'')
521 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
522 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
526 $sql =
'SELECT COALESCE(MAX(version), 0) + 1
527 FROM sq_file_vers_history
528 WHERE fileid = :fileid';
534 }
catch (Exception $e) {
535 throw new Exception(
'Unable to get version information for file ID '.$fileid.
' due to database error: '.$e->getMessage());
539 $date = ts_iso8601($now);
544 $sql =
'UPDATE sq_file_vers_history
545 SET to_date = :to_date
546 WHERE fileid = :fileid
547 AND to_date IS NULL';
552 $sql = str_replace(
':to_date', db_extras_todate(
MatrixDAL::getDbType(),
':to_date', FALSE), $sql);
558 }
catch (Exception $e) {
559 throw new Exception(
'Unable to update version history for file ID '.$fileid.
' due to database error: '.$e->getMessage());
562 $version = (int) $version;
563 if (file_exists($real_file)) {
564 $file_size = filesize($real_file);
565 $md5 = md5_file($real_file);
566 $sha1 = sha1_file($real_file);
575 $sql =
'INSERT INTO sq_file_vers_history
576 (fileid, version, from_date, to_date, file_size, md5, sha1, removal, extra_info)
578 (:fileid, :version, :from_date, :to_date, :file_size, :md5, :sha1, :removal, :extra_info)';
582 $sql = str_replace(
':from_date', db_extras_todate(
MatrixDAL::getDbType(),
':from_date', FALSE), $sql);
595 }
catch (Exception $e) {
596 throw new Exception(
'Unable to insert version history for file ID '.$fileid.
' due to database error: '.$e->getMessage());
600 if (file_exists($real_file)) {
602 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
603 $rep_dir = $this->_dir.
'/'.$rep_path;
604 if (!is_dir($rep_dir) && !create_directory($rep_dir)) {
606 throw new Exception(
'There is no repository folder for file #'.$fileid);
609 $rep_file = $rep_dir.
'/'.basename($real_file).
',ffv'.$version;
610 if (!copy($real_file, $rep_file)) {
611 throw new Exception(
'Can not copy file to repository for file #'.$fileid);
616 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
617 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
618 }
catch (Exception $e) {
619 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
620 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
642 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
644 $ffv_dir = dirname($real_file).
'/.FFV';
645 if (is_dir($ffv_dir) || create_directory($ffv_dir)) {
648 'dir="'.$this->_dir.
'"',
649 'fileid="'.$fileid.
'"',
650 'version="'.$version.
'"',
653 $ffv_file = $ffv_dir.
'/'.basename($real_file);
655 if (!file_exists($ffv_file) || rename($ffv_file, $ffv_file.
'.bup')) {
656 if (string_to_file(implode(
"\n", $ffv_lines).
"\n", $ffv_file)) {
657 if (file_exists($ffv_file.
'.bup')) {
658 unlink($ffv_file.
'.bup');
664 rename($ffv_file.
'.bup', $ffv_file);
667 trigger_localised_error(
'FVER0020', E_USER_NOTICE, $ffv_dir);
697 trigger_localised_error(
'FVER0007', E_USER_WARNING,$rep_file);
701 if (!$this->
_lockFile($info[
'fileid'])) {
702 trigger_localised_error(
'FVER0018', E_USER_NOTICE);
707 if (is_null($version)) {
709 if (is_null($date)) {
713 $sql =
'SELECT version, removal, md5, sha1
714 FROM sq_file_vers_history
715 WHERE fileid = :fileid
716 AND to_date IS NULL';
717 $nice_date = ts_iso8601(time());
719 $nice_date = ts_iso8601($date);
720 $date = ts_iso8601($date);
722 require_once SQ_FUDGE_PATH.
'/db_extras/db_extras.inc';
723 $sql =
'SELECT version, removal, md5, sha1
724 FROM sq_file_vers_history
725 WHERE fileid = :fileid
726 AND from_date <= :from_date_1
727 AND (to_date IS NULL OR to_date > :from_date_2)
728 ORDER BY version DESC';
734 $sql = str_replace(
':from_date_1', db_extras_todate(
MatrixDAL::getDbType(),
':from_date_1', FALSE), $sql);
735 $sql = str_replace(
':from_date_2', db_extras_todate(
MatrixDAL::getDbType(),
':from_date_2', FALSE), $sql);
740 if (!is_null($date)) {
746 if (!empty($result)) {
747 $ver_info = $result[0];
752 }
catch (Exception $e) {
753 throw new Exception(
'Unable to get versioning information for file ID '.$fileid.
' at version '.(is_null($version) ?
'(current)' : $version).
' due to database error: '.$e->getMessage());
756 if (empty($ver_info)) {
757 trigger_localised_error(
'FVER0006', E_USER_NOTICE, $rep_file, $nice_date);
764 $sql =
'SELECT version, removal, md5, sha1
765 FROM sq_file_vers_history
766 WHERE fileid = :fileid
767 AND version = :version';
775 if (!empty($result)) {
776 $ver_info = $result[0];
781 }
catch (Exception $e) {
782 throw new Exception(
'Unable to get versioning information for file ID '.$fileid.
' at version '.(is_null($version) ?
'(current)' : $version).
' due to database error: '.$e->getMessage());
785 if (empty($ver_info)) {
786 trigger_localised_error(
'FVER0005', E_USER_NOTICE, $rep_file);
794 $info[
'version'] = $ver_info[
'version'];
795 $info[
'removal'] = $ver_info[
'removal'];
796 $info[
'md5'] = $ver_info[
'md5'];
797 $info[
'sha1'] = $ver_info[
'sha1'];
798 $info[
'source_file'] = $this->_dir.
'/'.$rep_file.
',ffv'.$ver_info[
'version'];
832 $dir_prefix = $this->_dir.
'/';
833 if (substr($rep_file, 0, 1) !=
'/' && substr($rep_file, 0, strlen($dir_prefix)) != $dir_prefix) {
834 $rep_file = $dir_prefix.$rep_file;
837 $existing_version = $info[
'version'];
838 $exists = file_exists($rep_file.
',ffv'.$existing_version);
842 if ($info[
'md5'] && $info[
'sha1'] && trim($info[
'md5']) !==
'' && trim($info[
'sha1']) !==
'') {
843 $current = $rep_file.
',ffv'.$existing_version;
846 if (md5_file($current) != $info[
'md5'] || sha1_file($current) != $info[
'sha1']) {
853 if ($exists)
return true;
855 $destination = $rep_file.
',ffv'.$info[
'version'];
858 if (copy(SQ_DATA_PATH.
'/private/'.$info[
'path'].
'/'.$info[
'filename'], $destination)) {
860 trigger_localised_error(
'FVER0029', E_USER_WARNING, $info[
'version'], translate(
'data').
' '.translate(
'private'));
866 if (@copy(SQ_DATA_PATH.
'/public/'.$info[
'path'].
'/'.$info[
'filename'], $destination)) {
868 trigger_localised_error(
'FVER0029', E_USER_WARNING, $info[
'version'], translate(
'data').
' '.translate(
'public'));
875 while (!$exists && $existing_version > 0) {
877 $current = $rep_file.
',ffv'.$existing_version;
880 $exists = file_exists($current);
887 if (isset($ver_info[
'md5']) && isset($ver_info[
'sha1'])) {
888 $exists = md5_file($current) == $ver_info[
'md5'] && sha1_file($current) == $ver_info[
'sha1'];
894 if ($exists && @copy($current, $destination)) {
896 trigger_localised_error(
'FVER0029', E_USER_WARNING, $info[
'version'],
'ffv'.$existing_version);
901 trigger_localised_error(
'FVER0030', E_USER_WARNING);
922 $filesize = filesize($real_file);
923 $md5 = md5_file($real_file);
924 $sha1 = sha1_file($real_file);
926 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
927 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
933 'file_size' => $filesize,
935 'version' => $version,
938 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
939 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
941 }
catch (Exception $e) {
942 throw new Exception(
'Unable to update the filesize and hash information for fileid: '.$fileid.
' with version: '.$version.
' due to database error: '.$e->getMessage());
943 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
944 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
961 function checkOut($rep_file, $dest_dir, $version=null, $date=null)
964 if (!is_dir($dest_dir) || !is_writable($dest_dir)) {
965 trigger_localised_error(
'FVER0001', E_USER_NOTICE, $dest_dir);
970 if (empty($info) || $info == FUDGE_FV_NOT_CHECKED_OUT) {
974 $dest_file = $dest_dir.
'/'.basename($rep_file);
977 if (!$this->
_createFFVFile($dest_file, $info[
'fileid'], $info[
'version'])) {
982 if ($info[
'removal']) {
983 if (file_exists($dest_file) && !unlink($dest_file)) {
985 unlink($dest_dir.
'/.FFV/'.basename($rep_file));
991 if (!copy($info[
'source_file'], $dest_file)) {
993 unlink($dest_dir.
'/.FFV/'.basename($rep_file));
1015 function output($rep_file, $version=null, $date=null)
1018 if (empty($info))
return false;
1020 if ($info[
'removal']) {
1021 trigger_localised_error(
'FVER0013', E_USER_NOTICE, $rep_file);
1025 readfile($info[
'source_file']);
1043 if (!is_array($info)) {
1044 if ($info == FUDGE_FV_ERROR) {
1045 trigger_localised_error(
'FVER0002', E_USER_WARNING, __FUNCTION__);
1050 if (!$this->
_lockFile($info[
'fileid'])) {
1051 trigger_localised_error(
'FVER0018', E_USER_NOTICE);
1052 return FUDGE_FV_ERROR;
1056 if (empty($curr_ver_info)) {
1057 trigger_localised_error(
'FVER0026', E_USER_NOTICE, $real_file);
1058 return FUDGE_FV_ERROR;
1062 if (empty($file_ver_info)) {
1063 trigger_localised_error(
'FVER0009', E_USER_NOTICE, $info[
'version']);
1064 return FUDGE_FV_ERROR;
1067 $ret_val = ($curr_ver_info[
'version'] > $file_ver_info[
'version']) ? FUDGE_FV_OLD_VERSION : FUDGE_FV_CURRENT_VERSION;
1070 $ret_val |= ($this->
_fileModified($file_ver_info, $real_file)) ? FUDGE_FV_MODIFIED : FUDGE_FV_NOT_MODIFIED;
1089 $ver_info[
'file_size'] != filesize($real_file) ||
1090 $ver_info[
'md5'] != md5_file($real_file) ||
1091 $ver_info[
'sha1'] != sha1_file($real_file)
1109 if (!is_array($info)) {
1110 if ($info == FUDGE_FV_ERROR) {
1111 trigger_localised_error(
'FVER0002', E_USER_WARNING, __FUNCTION__);
1116 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1117 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1119 if (!$this->
_lockFile($info[
'fileid'])) {
1120 trigger_localised_error(
'FVER0018', E_USER_NOTICE);
1121 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1122 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1123 return FUDGE_FV_ERROR;
1128 if (empty($curr_ver_info)) {
1129 trigger_localised_error(
'FVER0011', E_USER_NOTICE, $info[
'path'], $info[
'filename']);
1131 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1132 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1133 return FUDGE_FV_ERROR;
1138 if (empty($file_ver_info)) {
1139 trigger_localised_error(
'FVER0010', E_USER_NOTICE, $info[
'version'], $info[
'path'], $info[
'filename']);
1141 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1142 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1143 return FUDGE_FV_ERROR;
1148 if ($curr_ver_info[
'version'] != $file_ver_info[
'version']) {
1149 trigger_localised_error(
'FVER0019', E_USER_NOTICE, $info[
'path'], $info[
'filename'], $file_ver_info[
'version'], $curr_ver_info[
'version']);
1151 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1152 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1153 return FUDGE_FV_ERROR;
1158 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1159 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1160 return FUDGE_FV_NOT_MODIFIED;
1164 $version = $this->
_updateFile($info[
'fileid'], $info[
'path'], $real_file, $extra_info);
1165 if (empty($version)) {
1167 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1168 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1169 return FUDGE_FV_ERROR;
1173 if (!$this->
_createFFVFile($real_file, $info[
'fileid'], $version)) {
1175 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1176 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1177 return FUDGE_FV_ERROR;
1182 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1183 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1199 function remove($real_file, $extra_info=
'')
1202 if (!is_array($info)) {
1203 if ($info == FUDGE_FV_ERROR) {
1204 trigger_localised_error(
'FVER0002', E_USER_WARNING, __FUNCTION__);
1209 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1210 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1212 if (!$this->
_lockFile($info[
'fileid'])) {
1213 trigger_localised_error(
'FVER0018', E_USER_NOTICE);
1214 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1215 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1216 return FUDGE_FV_ERROR;
1221 if (empty($curr_ver_info)) {
1222 trigger_localised_error(
'FVER0012', E_USER_NOTICE, $info[
'path'], $info[
'filename']);
1224 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1225 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1226 return FUDGE_FV_ERROR;
1231 if (empty($file_ver_info)) {
1232 trigger_localised_error(
'FVER0010', E_USER_NOTICE, $info[
'version'], $info[
'path'], $info[
'filename']);
1234 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1235 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1236 return FUDGE_FV_ERROR;
1241 if ($curr_ver_info[
'version'] != $file_ver_info[
'version']) {
1242 trigger_localised_error(
'FVER0023', E_USER_NOTICE, $info[
'path'], $info[
'filename'], $curr_ver_info[
'version']);
1244 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1245 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1246 return FUDGE_FV_ERROR;
1250 if ($this->
clearOut($real_file) == FUDGE_FV_ERROR) {
1252 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1253 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1254 return FUDGE_FV_ERROR;
1260 $version = $this->
_updateFile($info[
'fileid'], $info[
'path'], $real_file, $extra_info);
1261 if (empty($version)) {
1263 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1264 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1265 return FUDGE_FV_ERROR;
1269 if (!$this->
_createFFVFile($real_file, $info[
'fileid'], $version)) {
1271 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1272 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1273 return FUDGE_FV_ERROR;
1278 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1279 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1297 if (!is_array($info)) {
1298 if ($info == FUDGE_FV_ERROR) {
1299 trigger_localised_error(
'FVER0002', E_USER_WARNING, __FUNCTION__);
1305 if (!unlink(dirname($real_file).
'/.FFV/'.basename($real_file))) {
1306 return FUDGE_FV_ERROR;
1309 $file_removed = unlink($real_file);
1311 return ($file_removed) ? FUDGE_FV_OK : FUDGE_FV_ERROR;
1327 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1328 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1330 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
1334 if (!is_array($info)) {
1335 if ($info == FUDGE_FV_ERROR) {
1336 trigger_error(
'Error occured getting file information, unable to run '.__FUNCTION__.
'()', E_USER_WARNING);
1338 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1339 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1344 $old_path = $info[
'path'];
1345 $new_path = preg_replace(
'%/[^/]*/%',
'/'.$new_type_code.
'/', $old_path);
1349 $bind_vars = Array (
1350 'new_path' => $new_path,
1351 'old_path' => $old_path,
1354 }
catch (Exception $e) {
1355 throw new Exception(
'Unable to update pathname to: "'.$new_path.
'" for previous path: "'.$old_path.
'" due to database error: '.$e->getMessage());
1358 $new_dir = $this->_dir.
'/'.$new_path;
1360 if (!is_dir($new_dir)) create_directory($new_dir);
1362 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1363 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1365 return rename($this->_dir.
'/'.$old_path, $this->_dir.
'/'.$new_path);