Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
upgrade_form_submission_linking.php
1 <?php
23 error_reporting(E_ALL);
24 if ((php_sapi_name() != 'cli')) {
25  trigger_error("You can only run this script from the command line\n", E_USER_ERROR);
26 }
27 
28 $SYSTEM_ROOT = (isset($_SERVER['argv'][1])) ? $_SERVER['argv'][1] : '';
29 if (empty($SYSTEM_ROOT)) {
30  echo "ERROR: You need to supply the path to the System Root as the first argument\n";
31  exit();
32 }
33 
34 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.'/core/include/init.inc')) {
35  echo "ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
36  exit();
37 }
38 
39 require_once $SYSTEM_ROOT.'/core/include/init.inc';
40 
41 $root_user = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user');
42 
43 // log in as root
44 if (!$GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user)) {
45  echo "ERROR: Failed logging in as root user\n";
46  exit();
47 }
48 
49 $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
50 $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
51 
52 $am = $GLOBALS['SQ_SYSTEM']->am;
53 
54 $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
55 
56 $ecommerce_formids = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids('form_ecommerce', FALSE);
57 
58 $formids = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids('form', FALSE);
59 foreach ($formids as $formid) {
60  $form = $am->getAsset($formid);
61 
62  if (in_array($formid, $ecommerce_formids)) continue;
63 
64  pre_echo('Moving submissions for '.$form->name.' ('.$form->id.') to submissions folder');
65  $submissions_folder = $form->getSubmissionsFolder();
66  if (is_null($submissions_folder)) {
67  trigger_error('Submissions folder not found for form #'.$formid.'; upgrade may be required', E_USER_ERROR);
68  }
69  $submission_links = $am->getLinks($formid, SQ_SC_LINK_ALL, 'form_submission', FALSE);
70  foreach ($submission_links as $link) {
71  $am->moveLink($link['linkid'], $submissions_folder->id, $link['link_type'], $link['sort_order']);
72  }
73 }
74 
75 $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
76 
77 $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');