function echo_comment($msg, $pre = 0)
{
    echo "<!--";
    if ($pre) {
        pre_echo($msg);
    } else {
        echo $msg;
    }
    echo "-->";
}
    $keys = implode(',', $table_info['primary_key']);
    if (isset($table_info['unique_key'])) {
        $keys = $keys . ',' . implode(',', $table_info['unique_key']);
    }
    if (empty($keys)) {
        continue;
    }
    echo "Checking table sq_rb_" . $table . ' ... ';
    $sql = 'SELECT ' . $keys . ', sq_eff_to, count(*) as occ FROM sq_rb_' . $table . ' GROUP BY ' . $keys . ', sq_eff_to HAVING count(*) > 1';
    $results = MatrixDAL::executeSqlAssoc($sql);
    if (empty($results)) {
        echo '[ OK ]';
    } else {
        echo count($results) . ' set(s) of overlapping entries found. ';
        if ($show_overlapping_entries) {
            pre_echo($results);
        }
        echo '[ NOT OK ]';
        if ($fix_overlapping_entries && ($fix_table == $table || $fix_table == 'all')) {
            echo "\nFixing the rollback table sq_rb_" . $table;
            $table_fixed = fix_rollback_table($table, $table_info, $results);
            echo ' [ ' . ($table_fixed ? 'FIXED' : 'FAILED') . ' ]';
            echo "\n";
        }
    }
    echo "\n";
}
//end foreach
// END OF MAIN PROGRAM
/**
* Fix rollback table
/**
* Actually perform the changes to the files
*
* @param string	$root_node			Asset ID of the root node to search for Files from
* @param int	$setting			The unrestricted setting to change assets to
*									(0 = restricted, 1 = unrestricted)
* @param array	$file_assretids		assetid of all the file type assets found under the root node
*
* @return void
*/
function do_set_unrestricted($root_node, $setting, $file_assetids)
{
    $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
    $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
    $return = array('changed' => 0, 'failed' => 0);
    $root_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($root_node);
    $child_query = $GLOBALS['SQ_SYSTEM']->am->generateGetChildrenQuery($root_asset, 'file', FALSE);
    // Children query normally selects asset ID and type code. We don't want type code.
    $child_query['sql_array']['select'] = str_replace(', a.type_code', '', $child_query['sql_array']['select']);
    $child_query['sql_array']['union_select'] = str_replace(', null AS type_code', '', $child_query['sql_array']['union_select']);
    $sql = 'SELECT assetid FROM sq_ast_attr_val';
    $where = ' WHERE assetid IN (' . implode(' ', $child_query['sql_array']) . ')
				AND attrid IN (SELECT attrid FROM sq_ast_attr
					WHERE type_code IN (SELECT type_code FROM sq_ast_typ_inhd
						WHERE inhd_type_code = :inhd_type_code)
					AND name = :attr_name)
				AND custom_val <> :setting';
    $bind_vars = array('inhd_type_code' => 'file', 'attr_name' => 'allow_unrestricted', 'setting' => (int) $setting);
    // Get the assets (so we can update their lookups later)\
    try {
        status_message_start('Finding files to change...');
        $bind_vars = array_merge($bind_vars, $child_query['bind_vars']);
        $query = MatrixDAL::preparePdoQuery($sql . $where);
        foreach ($bind_vars as $bind_var => $bind_value) {
            MatrixDAL::bindValueToPdo($query, $bind_var, $bind_value);
        }
        $result = array_keys(MatrixDAL::executePdoGroupedAssoc($query));
    } catch (Exception $e) {
        status_message_result('DB ERROR');
        throw new Exception('Database error: ' . $e->getMessage());
    }
    // bug fix #4649 set_files_unrestricted.php doesn't change any assets
    // since we have all the file type asset's assetid we will check and
    // see if any of them has the attributes not set
    $sql_query = 'SELECT assetid FROM sq_ast_attr_val l WHERE l.assetid IN (\'' . implode('\', \'', array_keys($file_assetids)) . '\') AND l.attrid IN (SELECT attrid FROM sq_ast_attr WHERE type_code IN (SELECT type_code FROM sq_ast_typ_inhd WHERE inhd_type_code = \'file\') AND name = \'allow_unrestricted\')';
    $good_assets = MatrixDAL::executeSqlAssoc($sql_query);
    $additional_assets = array_keys($file_assetids);
    foreach ($good_assets as $good_asset) {
        foreach ($additional_assets as $index => $additional_asset) {
            if ($additional_assets[$index] == $good_asset['assetid']) {
                unset($additional_assets[$index]);
            }
        }
    }
    status_message_result(count($result) + count($additional_assets) . ' assets to update');
    // If there were any assets, update them in one hit, and then update
    // the lookups
    if (count($result) + count($additional_assets) > 0) {
        status_message_start('Updating attributes...');
        // update
        try {
            $update_sql = 'UPDATE sq_ast_attr_val SET custom_val = :new_setting';
            $bind_vars['new_setting'] = (int) $setting;
            $query = MatrixDAL::preparePdoQuery($update_sql . $where);
            foreach ($bind_vars as $bind_var => $bind_value) {
                MatrixDAL::bindValueToPdo($query, $bind_var, $bind_value);
            }
            MatrixDAL::execPdoQuery($query);
            status_message_result('OK');
        } catch (Exception $e) {
            status_message_result('DB ERROR');
            throw new Exception('Database error: ' . $e->getMessage());
        }
        // insert
        foreach ($additional_assets as $additional_asset) {
            $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($additional_asset);
            $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
            $asset->setAttrValue('allow_unrestricted', (int) $setting);
            $asset->saveAttributes(TRUE);
            $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
        }
        $assetids_to_update = array_merge($result, $additional_assets);
        $deja_vu = $GLOBALS['SQ_SYSTEM']->getDejaVu();
        if ($deja_vu->enabled()) {
            foreach ($assetids_to_update as $assetid) {
                $deja_vu->forget('asset', $assetid);
            }
            //end foreach
        }
        //end if
        // Now update lookups
        status_message_start('Updating lookups...');
        $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
        $vars = array('assetids' => $assetids_to_update);
        $errors = $hh->freestyleHipo('hipo_job_update_lookups', $vars);
        if (empty($errors)) {
            status_message_result('OK');
        } else {
            status_message_result('ERRORS');
            pre_echo($errors);
        }
    }
    $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
    $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
}
					 AND url LIKE :from_url || \'/__data/%\')';
        $query = MatrixDAL::preparePdoQuery($sql);
        MatrixDAL::bindValueToPdo($query, 'site_assetid', $from_site_assetid);
        MatrixDAL::bindValueToPdo($query, 'from_url', $matching_from_roots[$x]);
        MatrixDAL::execPdoQuery($query);
        $sql = 'DELETE FROM sq_ast_lookup WHERE assetid IN (SELECT minorid FROM sq_ast_lnk WHERE linkid IN (SELECT linkid FROM sq_ast_lnk_tree t1 WHERE treeid LIKE (SELECT treeid || \'_%\' FROM sq_ast_lnk_tree t2 WHERE linkid IN (SELECT linkid FROM sq_ast_lnk WHERE minorid = :site_assetid) ' . $limit_clause . ')))
					AND url LIKE :from_url || \'/__data/%\'';
        $query = MatrixDAL::preparePdoQuery($sql);
        MatrixDAL::bindValueToPdo($query, 'site_assetid', $from_site_assetid);
        MatrixDAL::bindValueToPdo($query, 'from_url', $matching_from_roots[$x]);
        MatrixDAL::execPdoQuery($query);
    }
    //end for - remaining from URLs
}
//end if - no static root set
pre_echo('LOOKUPS CHANGED FROM ' . $from_url . ' TO ' . $to_url);
$GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
$GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
/**
* Prints the specified prompt message and returns the line from stdin
*
* @param string	$prompt	the message to display to the user
*
* @return string
* @access public
*/
function get_line($prompt = '')
{
    echo $prompt;
    // now get their entry and remove the trailing new line
    return rtrim(fgets(STDIN, 4096));
$rebakeCmd = "/usr/bin/php {$SYSTEM_ROOT}/scripts/rebake.php {$SYSTEM_ROOT}";
echo "rebake.php now needs to run. Do this now [Y/n] ? ";
$response = strtolower(trim(fgets(STDIN)));
if (empty($response) === TRUE) {
    $response = 'y';
}
if ($response != 'y') {
    pre_echo("You will need to run {$rebakeCmd} manually.\n");
    exit;
}
echo "Running rebake.php now .. \n";
$output = array();
$rc = -1;
exec($rebakeCmd, $output, $rc);
pre_echo("Rebake returned the following:\n" . implode("\n", $output) . "\n");
pre_echo('This script is now finished.');
/**
 * parse_tables_xml
 * Parse the appropriate xml file based on the type of db we're dealing with.
 *
 * @param String $xml_file The name of the xml file to parse
 * @param String $dest_db The destination db type ('pgsql', 'oci').
 *
 * @return Array Returns a large array of the tables, sequences, indexes appropriate for that db type.
 */
function parse_tables_xml($xml_file, $dest_db)
{
    try {
        $root = simplexml_load_string(file_get_contents($xml_file), 'SimpleXMLElement', LIBXML_NOCDATA);
    } catch (Exception $e) {
        throw new Exception('Could not parse tables XML file: ' . $e->getMessage());
    echo "ERROR: You need to supply the path to the System Root as the first argument\n";
    exit;
}
if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT . '/core/include/init.inc')) {
    echo "ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
    exit;
}
$ASSETID = isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : '';
require_once $SYSTEM_ROOT . '/core/include/init.inc';
require_once SQ_INCLUDE_PATH . '/general_occasional.inc';
$root_user =& $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user');
if (is_null($root_user)) {
    echo "Unable to get Root User\n";
    exit;
}
if (!$GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user)) {
    echo "Unable to set Root User as current user\n";
    exit;
}
$cron_job =& $GLOBALS['SQ_SYSTEM']->am->getAsset($ASSETID);
if (is_null($cron_job)) {
    echo "Asset ID passed (#'.{$ASSETID}.') does not point to a valid asset\n";
    exit;
}
if (!is_a($cron_job, 'cron_job')) {
    echo "Asset ID passed (#'.{$ASSETID}.') does not point to a Cron Job asset";
    exit;
}
$result = $cron_job->run();
pre_echo("Result: " . implode(', ', get_bit_names('SQ_CRON_JOB_', $result, true)));
    if (empty($info) === TRUE) {
        continue;
    }
    $extra_message_shown = true;
    $show_extra_indexes_message = true;
    $extra_indexes_message .= "These were found on table " . $tablename . ":\n";
    foreach ($info as $index_name => $fields) {
        $extra_indexes_message .= "\tDROP INDEX " . $index_name . ";\n";
    }
    $extra_indexes_message .= "\n";
}
if ($show_extra_indexes_message) {
    pre_echo(trim($extra_indexes_message));
}
if (!$extra_message_shown) {
    pre_echo('Everything has been checked and no problems were found.');
}
/**
 * parse_tables_xml
 * Parse the appropriate xml file based on the type of db we're dealing with.
 *
 * @param String $xml_file The name of the xml file to parse
 * @param String $db_type The db type ('pgsql', 'oci').
 *
 * @return Array Returns a large array of the tables, sequences, indexes appropriate for that db type.
 */
function parse_tables_xml($xml_file, $db_type)
{
    $dbtype = _getDbType();
    try {
        $root = simplexml_load_string(file_get_contents($xml_file), 'SimpleXMLElement', LIBXML_NOCDATA);
}
require_once $SYSTEM_ROOT . '/core/include/init.inc';
$root_user = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user');
// log in as root
if (!$GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user)) {
    echo "ERROR: Failed logging in as root user\n";
    exit;
}
$GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
$GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
$am = $GLOBALS['SQ_SYSTEM']->am;
$GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
$ecommerce_formids = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids('form_ecommerce', FALSE);
$formids = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids('form', FALSE);
foreach ($formids as $formid) {
    $form = $am->getAsset($formid);
    if (in_array($formid, $ecommerce_formids)) {
        continue;
    }
    pre_echo('Moving submissions for ' . $form->name . ' (' . $form->id . ') to submissions folder');
    $submissions_folder = $form->getSubmissionsFolder();
    if (is_null($submissions_folder)) {
        trigger_error('Submissions folder not found for form #' . $formid . '; upgrade may be required', E_USER_ERROR);
    }
    $submission_links = $am->getLinks($formid, SQ_SC_LINK_ALL, 'form_submission', FALSE);
    foreach ($submission_links as $link) {
        $am->moveLink($link['linkid'], $submissions_folder->id, $link['link_type'], $link['sort_order']);
    }
}
$GLOBALS['SQ_SYSTEM']->restoreRunLevel();
$GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
Example #9
0
} else {
    print_status_name('Installing queries for installed assets (' . count($asset_types) . ' assets)...');
    try {
        foreach ($asset_types as $type_code) {
            MatrixDALBaker::addAssetTypeQueries($type_code);
            MatrixDALBaker::bakeQueriesFile($type_code);
        }
        print_status_result('OK');
    } catch (Exception $e) {
        print_status_result('FAILED');
        echo '(Exception at ' . $type_code . ' asset: ' . $e->getMessage() . ')' . "\n";
        exit(1);
    }
}
ini_set('include_path', $old_path);
pre_echo('Query Installation Complete');
exit(0);
/**
* Gets a list of supplied package options from the command line arguments given
*
* Returns an array in the format needed for package_list
*
* @param array	$options	the options as retrieved from Console::getopts
*
* @return array
* @access public
*/
function get_console_list($options)
{
    $list = array();
    foreach ($options as $option) {