24 error_reporting(E_ALL);
27 if ((php_sapi_name() ==
'cli')) {
28 if (isset($_SERVER[
'argv'][1])) $SYSTEM_ROOT = $_SERVER[
'argv'][1];
29 $err_msg =
"You need to supply the path to the System Root as the first argument\n";
32 if (isset($_GET[
'SYSTEM_ROOT'])) $SYSTEM_ROOT = $_GET[
'SYSTEM_ROOT'];
34 <div style="background-color: red; color: white; font-weight: bold;">
35 You need to supply the path to the System Root as a query string variable called SYSTEM_ROOT
40 if (empty($SYSTEM_ROOT)) {
45 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
46 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
51 function get_line($prompt=
'')
55 return rtrim(fgets(STDIN, 4094));
60 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
62 if ((php_sapi_name() ==
'cli')) {
63 if (isset($_SERVER[
'argv'][2])) {
64 $old_system_root = rtrim(trim($_SERVER[
'argv'][2]),
'/');
65 if (strtolower(get_line(
'Confirm "'.$old_system_root.
'" (Y/N) : ')) !=
'y') {
66 unset($old_system_root);
71 if (!isset($old_system_root)) {
73 $old_system_root = get_line(
'Enter the old System Root : ');
74 }
while (strtolower(get_line(
'Confirm "'.$old_system_root.
'" (Y/N) : ')) !=
'y');
79 $new_system_root = $SYSTEM_ROOT;
81 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
82 function recurse_find_ffv_files($dir, $old_rep_root, $new_rep_root)
85 while (
false !== ($entry = $d->read())) {
86 if ($entry ==
'.' || $entry ==
'..')
continue;
89 if (is_dir($dir.
'/'.$entry)) {
91 if ($entry ==
'.FFV') {
93 $ffv_dir = $dir.
'/'.$entry;
94 $ffv_d = dir($ffv_dir);
95 while (
false !== ($ffv_entry = $ffv_d->read())) {
96 if ($ffv_entry ==
'.' || $ffv_entry ==
'..')
continue;
99 if (is_file($ffv_dir.
'/'.$ffv_entry)) {
100 $ffv_file = $ffv_dir.
'/'.$ffv_entry;
101 $str = file_to_string($ffv_file);
103 $str = str_replace(
'dir="'.$old_rep_root.
'"',
'dir="'.$new_rep_root.
'"', $str);
104 echo
"File : $ffv_file\n";
105 #pre_echo("FILE : $ffv_file\n CONTENTS : \n$str");
106 string_to_file($str, $ffv_file);
114 recurse_find_ffv_files($dir.
'/'.$entry, $old_rep_root, $new_rep_root);
124 $old_rep_path = preg_replace(
'|/+$|',
'', $old_system_root).
'/data/file_repository';
125 $new_rep_path = preg_replace(
'|/+$|',
'', $new_system_root).
'/data/file_repository';
127 pre_echo(
"OLD : $old_rep_path\nNEW : $new_rep_path");
129 recurse_find_ffv_files(SQ_DATA_PATH.
'/private', $old_rep_path, $new_rep_path);
130 recurse_find_ffv_files(SQ_DATA_PATH.
'/public', $old_rep_path, $new_rep_path);
132 $old_data_private_path = preg_replace(
'|/+$|',
'', $old_system_root).
'/data/';
133 $new_data_private_path = preg_replace(
'|/+$|',
'', $new_system_root).
'/data/';
135 recurse_data_dir_for_safe_edit_files(SQ_DATA_PATH.
'/private', $old_data_private_path, $new_data_private_path);
136 recurse_data_dir_for_safe_edit_files(SQ_DATA_PATH.
'/public', $old_data_private_path, $new_data_private_path);
139 echo
"Updating Form Submission file paths\n";
140 $new_root = preg_replace(
'|/+$|',
'', $new_system_root);
141 $old_root = preg_replace(
'|/+$|',
'', $old_system_root);
142 pre_echo(
"OLD : $old_root\nNEW : $new_root");
143 update_form_submission_filepaths($old_root, $new_root);
145 function recurse_data_dir_for_safe_edit_files($dir, $old_rep_root, $new_rep_root)
148 $index_to_look = Array (
'data_path',
'data_path_public');
149 while (
false !== ($entry = $d->read())) {
150 if ($entry ==
'.' || $entry ==
'..')
continue;
152 if (is_dir($dir.
'/'.$entry)) {
154 if ($entry ==
'.sq_system') {
155 $sq_system_dir = $dir.
'/'.$entry;
156 $sq_system_d = dir($sq_system_dir);
157 while (
false !== ($sq_system_entry = $sq_system_d->read())) {
158 if ($sq_system_entry ==
'.' || $sq_system_entry ==
'..' || $sq_system_entry !=
".object_data")
continue;
160 if (is_file($sq_system_dir.
'/'.$sq_system_entry)) {
161 $sq_system_file = $sq_system_dir.
'/'.$sq_system_entry;
162 $str = file_to_string($sq_system_file);
164 echo
"File : $sq_system_file\n";
165 preg_match (
"/\"[A-Za-z_0-9]+\"/" ,$str , $asset_type);
166 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(str_replace(
'"',
'', $asset_type[0]));
167 $content_array = unserialize($str);
168 foreach ($index_to_look as $value) {
169 $content_array->$value = str_replace($old_rep_root, $new_rep_root, $content_array->$value);
171 $str = serialize($content_array);
172 string_to_file($str, $sq_system_file);
176 $sq_system_d->close();
179 recurse_data_dir_for_safe_edit_files($dir.
'/'.$entry, $old_rep_root, $new_rep_root);
188 function update_form_submission_filepaths($old_root, $new_root){
190 $root_user =& $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
191 $GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user);
192 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
194 $children = $GLOBALS[
'SQ_SYSTEM']->am->getChildren(1,
'form_submission');
195 foreach (array_keys($children) as $child_id) {
196 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($child_id);
197 $data = $asset->attr(
'attributes');
198 if (isset($data[
'answers'])) {
199 foreach (array_keys($data[
'answers']) as $question_id) {
200 $extra_data = $asset->getExtraData($question_id);
201 if (!empty($extra_data[
'temp_filesystem_path'])) {
202 $path = $extra_data[
'temp_filesystem_path'];
203 $new_path = preg_replace(
"%$old_root%", $new_root, $path, 1);
204 if ($new_path != NULL){
205 if (strcmp($new_path, $path) != 0) {
206 $extra_data[
'temp_filesystem_path'] = $new_path;
207 if ($asset->setExtraData($question_id, $extra_data)){
208 $asset->saveAttributes();
209 echo
"Updated Form Submission ID: $asset->id\n";
213 echo
"Failed to update Form Submission ID: $asset->id\n";
216 if (!empty($extra_data[
'filesystem_path'])) {
217 $path = $extra_data[
'filesystem_path'];
218 $new_path = preg_replace(
"%$old_root%", $new_root, $path, 1);
219 if ($new_path != NULL){
220 if (strcmp($new_path, $path) != 0) {
221 $extra_data[
'filesystem_path'] = $new_path;
222 if ($asset->setExtraData($question_id, $extra_data)){
223 $asset->saveAttributes();
224 echo
"Updated Form Submission ID: $asset->id\n";
228 echo
"Failed to update Form Submission ID: $asset->id\n";
235 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
236 $GLOBALS[
'SQ_SYSTEM']->restoreCurrentUser();