Ejemplo n.º 1
0
        $primary_url = $site_network->getPrimaryURL();
    }
}
if ($primary_url == sq_web_path('root_url')) {
    // if the actual script execution is happening in the primary
    // url, we want to update the time to persuade the overriding
    // of the secondary session files
    if (isset($_GET['in_primary']) && $_GET['in_primary']) {
        $_SESSION['SQ_SESSION_TIMESTAMP'] = time();
        exit;
    }
    // see design.inc and pre_session.php
    // on how we call this function when we move from one site to another
    echo 'var SESSIONID = "' . session_id() . '";';
    ?>
	function start_session_handler(url) {
		JsHttpConnector.submitRequest(url, null, 'sessionid=' + SESSIONID);
	}
	<?php 
} else {
    if (!isset($_REQUEST['sessionid']) || !preg_match('/^[a-z0-9]+$/i', $_REQUEST['sessionid'])) {
        // something is definately wrong
        trigger_localised_error('SYS0013', translate('Missing primary sessionid'), E_USER_ERROR);
    }
    if (is_null($site_network)) {
        trigger_localised_error('SYS0014', translate('Missing site network'), E_USER_ERROR);
    }
    $session_handler_instance = new $session_handler();
    $session_handler_instance->syncSession($_REQUEST['sessionid']);
}
//end if
}
//end if
if (!$fm->attr('indexing')) {
    echo "\n\nBEFORE RUNNING THE SCRIPT, PLEASE CHECK THAT THE INDEXING STATUS IS TURNED ON\n";
    echo 'Note: You can change this option from the backend "System Management" > "Funnelback Manager" > "Details"' . "\n\n";
    exit;
}
// stop the script if the root collection is not specified or the collection that is specified isn't set
if (!empty($root_collection) && !isset($collections[$root_collection])) {
    echo "\n\nInvalid Collection ID passed in\n";
    exit;
}
//end if
// Check for a lock file
if (file_exists(SQ_TEMP_PATH . '/funnelback.indexer')) {
    trigger_localised_error('FNB0019', translate('Lockfile found. Scripts cannot be run concurrently.'), E_USER_WARNING);
    exit;
}
//end if
// Create a lock file
touch(SQ_TEMP_PATH . '/funnelback.indexer');
// Start indexing
$hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
$vars = array('collections' => empty($root_collection) ? array() : $root_collection);
$errors = $hh->freestyleHipo('hipo_job_funnelback_reindex', $vars, SQ_PACKAGES_PATH . '/funnelback/hipo_jobs');
if (!empty($errors)) {
    echo 'Funnelback Reindexing FAILED' . "\n";
    foreach ($errors as $error) {
        $line = array_get_index($error, 'message', '');
        if (!empty($line)) {
            echo $line . "\n";
$ms->openLog();
foreach ($_FILES as $id => $details) {
    if (is_array($details['name'])) {
        foreach ($_FILES[$id]['name'] as $index => $name) {
            if (!empty($name)) {
                $file_name = strtolower(str_replace(' ', '_', $name));
                while (file_exists(SQ_TEMP_PATH . '/' . $file_name)) {
                    $file_name = increment_filename($file_name);
                }
                if (move_uploaded_file($_FILES[$id]['tmp_name'][$index], SQ_TEMP_PATH . '/' . $file_name)) {
                    print "\nOK " . $file_name . "\n";
                } else {
                    trigger_localised_error('SYS0009', translate('Error uploading file %s'), E_USER_WARNING);
                }
            }
        }
    } else {
        if (!empty($details['name'])) {
            $file_name = strtolower(str_replace(' ', '_', $details['name']));
            while (file_exists(SQ_TEMP_PATH . '/' . $file_name)) {
                $file_name = increment_filename($file_name);
            }
            if (move_uploaded_file($_FILES[$id]['tmp_name'], SQ_TEMP_PATH . '/' . $file_name)) {
                print "\nOK " . $file_name . "\n";
            } else {
                trigger_localised_error('SYS0009', translate('Error uploading file %s'), E_USER_WARNING);
            }
        }
    }
}
$ms->closeLog();
/**
 * _updateFile
 * Update the target file by removing it first and then replace with a new file, update file versioning of it
 *
 * @return Boolean
 */
function _updateFile($new_file, $file_name, $data_path, $data_path_suffix)
{
    require_once SQ_FUDGE_PATH . '/general/file_system.inc';
    $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
    $file_path = $data_path . '/' . $file_name;
    if (!unlink($file_path)) {
        trigger_error('failed to remove old file ' . $file_name);
        return FALSE;
    }
    if (string_to_file(file_get_contents($new_file), $file_path)) {
        // add a new version to the repository
        $file_status = $fv->upToDate($file_path);
        if (FUDGE_FV_MODIFIED & $file_status) {
            if (!$fv->commit($file_path, '')) {
                trigger_localised_error('CORE0160', translate('Failed committing file version'), E_USER_WARNING);
            }
        }
    } else {
        trigger_error('Can not overwrite old file ' . $file_name);
    }
    // make sure we have the latest version of our file
    if (!$fv->checkOut($data_path_suffix . '/' . $file_name, $data_path)) {
        trigger_localised_error('CORE0032', translate('Failed checking out latest version of file'), E_USER_WARNING);
        return FALSE;
    }
    //end if
    return TRUE;
}
Ejemplo n.º 5
0
if (is_null($root_user)) {
    trigger_localised_error('CRON0023', translate('Unable to get Root User'), E_USER_ERROR);
}
if (!$GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user)) {
    trigger_localised_error('CRON0022', translate('Unable to set root user as the current user'), E_USER_ERROR);
}
$cron_mgr = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('cron_manager');
if (is_null($cron_mgr)) {
    trigger_localised_error('CRON0021', translate('Unable to get the Cron Manager'), E_USER_ERROR);
}
if (!empty($_SERVER['argv'][1]) && $_SERVER['argv'][1] == 'RESET_RUNNING') {
    if (!$GLOBALS['SQ_SYSTEM']->am->acquireLock($cron_mgr->id, 'attributes', 0, TRUE)) {
        trigger_localised_error('CRON0016', sprintf(translate('Unable to acquire lock of "%s"'), $cron_mgr->name), E_USER_ERROR);
    }
    if (!$cron_mgr->setAttrValue('running', FALSE)) {
        trigger_localised_error('CRON0010', translate('SET RUNNING FAILED'), E_USER_ERROR);
    }
    $GLOBALS['SQ_SYSTEM']->am->releaseLock($cron_mgr->id, 'attributes');
}
$cron_mgr->run();
exit(0);
/**
* Make a proper unix path (ripped from remote content)
*
* Works similar to php's realpath(), but doesn't rely on a file system
* Given a string representing a path, it tries to remove the relative references
* in short: given "/this/dir/../another/file.php" will produce "/this/another/file.php"
**
* NOTE: paths that try to jump outside the root will produce possibly erroneous result
* eg.: "/root/dir/../../../another/file.php" will become "/another/file.php"
* this behaviour is similar to how browsers treat relative paths
/**
* Gets the children of the root nodes in the correct order from highest in the tree first to the
* lowest. Taken from HIPO_Job_Update_Lookups->prepare().
*
* @return array
* @access public
*/
function getTreeSortedChildren($assetids)
{
    $db = MatrixDAL::getDb();
    $todo_normal = array();
    $todo_shadows = array();
    foreach ($assetids as $assetid) {
        // check if we are updating lookups for a shadow asset, or a bridge
        $id_parts = explode(':', $assetid);
        if (isset($id_parts[1])) {
            $todo_shadows = array_merge($todo_shadows, array_keys($GLOBALS['SQ_SYSTEM']->am->getChildren($assetid)));
        } else {
            $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
            if ($asset instanceof Bridge) {
                if (!method_exists($asset, 'getChildren')) {
                    trigger_localised_error('SYS0204', translate('Shadow asset handler "%s" can not get children'), E_USER_WARNING, $asset->name);
                } else {
                    $todo_shadows = array_merge($todo_shadows, array_keys($asset->getChildren($assetid)));
                }
            }
            $where = 'l.minorid = :assetid';
            $where = $GLOBALS['SQ_SYSTEM']->constructRollbackWhereClause($where, 't');
            $where = $GLOBALS['SQ_SYSTEM']->constructRollbackWhereClause($where, 'l');
            $sql = 'SELECT t.treeid
					FROM ' . SQ_TABLE_RUNNING_PREFIX . 'ast_lnk_tree t INNER JOIN ' . SQ_TABLE_RUNNING_PREFIX . 'ast_lnk l ON t.linkid = l.linkid
					' . $where;
            $sql = db_extras_modify_limit_clause($sql, MatrixDAL::getDbType(), 1);
            try {
                $query = MatrixDAL::preparePdoQuery($sql);
                MatrixDAL::bindValueToPdo($query, 'assetid', $assetid);
                $treeid = MatrixDAL::executePdoOne($query);
            } catch (Exception $e) {
                throw new Exception('Unable to get treeid for minorid: ' . $assetid . ' due to database error: ' . $e->getMessage());
            }
            $sql = 'SELECT l.minorid, MAX(LENGTH(t.treeid)) as length
					FROM ' . SQ_TABLE_RUNNING_PREFIX . 'ast_lnk_tree t
							 INNER JOIN ' . SQ_TABLE_RUNNING_PREFIX . 'ast_lnk l ON t.linkid = l.linkid
					';
            $where = 't.treeid LIKE :treeid
					  GROUP BY l.minorid ORDER BY length';
            $where = $GLOBALS['SQ_SYSTEM']->constructRollbackWhereClause($where, 't');
            $where = $GLOBALS['SQ_SYSTEM']->constructRollbackWhereClause($where, 'l');
            try {
                $query = MatrixDAL::preparePdoQuery($sql . $where);
                MatrixDAL::bindValueToPdo($query, 'treeid', $treeid . '%');
                $new_assets = MatrixDAL::executePdoAssoc($query);
            } catch (Exception $e) {
                throw new Exception('Unable to get minorids for treeid: ' . $treeid[0]['treeid'] . ' due to database error: ' . $e->getMessage());
            }
            $todo_normal = array_merge($todo_normal, $new_assets);
        }
        //end else
    }
    //end foreach
    // Make sure lower assets are done after higher ones
    usort($todo_normal, create_function('$a, $b', 'return $a[\'length\'] > $b[\'length\'];'));
    $todo_assetids = array();
    foreach ($todo_normal as $asset_info) {
        $todo_assetids[] = $asset_info['minorid'];
    }
    $todo_assetids = array_unique(array_merge($todo_assetids, $todo_shadows));
    return $todo_assetids;
}
/**
* Returns the information from the checked out files .FFV dir entry
* Returns either an error code or the info
*
* @param File_Versioning $file_versioning	the File_Versioning object
* @param string	$real_file	the checked out filename (ie the path to it on the filesystem)
*
* @return mixed int|array
* @access private
* @see _getFileInfoFromRealFile() in file_versioning.inc
*/
function _getFileInfoFromRealFile($file_versioning, $real_file)
{
    $ffv_dir = dirname($real_file) . '/.FFV';
    if (!is_dir($ffv_dir)) {
        return FUDGE_FV_NOT_CHECKED_OUT;
    }
    $ffv_file = $ffv_dir . '/' . basename($real_file);
    if (!is_file($ffv_file)) {
        return FUDGE_FV_NOT_CHECKED_OUT;
    }
    $ffv = parse_ini_file($ffv_file);
    if (!is_array($ffv)) {
        trigger_localised_error('FVER0025', translate('File Versioning information corrupt'), E_USER_WARNING);
        return FUDGE_FV_ERROR;
    }
    return $ffv;
}
/**
 * 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());
    }
    if ($root->getName() != 'schema' || !isset($root->tables) || !isset($root->sequences)) {
        throw new Exception('Tables XML file is not valid.');
        trigger_localised_error('SYS0012', translate('Invalid Schema for DB install'), E_USER_WARNING);
        return FALSE;
    }
    $info = array();
    $info['tables'] = array();
    $info['sequences'] = array();
    //--        TABLES        --//
    foreach ($root->tables->table as $table) {
        $table_name = (string) $table->attributes()->name;
        $info['tables'][$table_name] = array();
        $info['tables'][$table_name]['rollback'] = $table->attributes()->{'require_rollback'} == 1 ? TRUE : FALSE;
        //--        TABLE COLUMNS        --//
        $info['tables'][$table_name]['columns'] = array();
        foreach ($table->columns->column as $table_column) {
            $column_name = (string) $table_column->attributes()->name;
            $info['tables'][$table_name]['columns'][$column_name] = array();
            $info['tables'][$table_name]['columns'][$column_name]['allow_null'] = $table_column->attributes()->{'allow_null'} == 1 ? TRUE : FALSE;
            //--        TABLE COLUMN VARS        --//
            $type = NULL;
            $default = NULL;
            foreach ($table_column->children() as $column_var) {
                switch (strtolower($column_var->getName())) {
                    case 'type':
                        // set the type of the column if it hasnt already been
                        // set in a variation (this is the default column type)
                        if (is_null($type)) {
                            $type = (string) $column_var;
                        }
                        break;
                    case 'type_variations':
                        // check for varitions of the column type for his database
                        foreach ($column_var->children() as $variation) {
                            if ($variation->getName() == _getDbType(false, $dest_db)) {
                                $type = (string) $variation;
                                break;
                            }
                        }
                        break;
                    case 'default':
                        if (trim((string) $column_var) != '') {
                            $default = (string) $column_var;
                        }
                        break;
                    default:
                        continue;
                        break;
                }
            }
            $info['tables'][$table_name]['columns'][$column_name]['type'] = $type;
            $info['tables'][$table_name]['columns'][$column_name]['default'] = $default;
            //--        KEYS        --//
            $info['tables'][$table_name]['primary_key'] = array();
            $info['tables'][$table_name]['unique_key'] = array();
            if (isset($table->keys) && count($table->keys->children()) > 0) {
                foreach ($table->keys->children() as $table_key) {
                    $index_db_type = $table_key->attributes()->db;
                    if (!is_null($index_db_type) && (string) $index_db_type != _getDbType(false, $dest_db)) {
                        continue;
                    }
                    // work out the columns in this key
                    $key_columns = array();
                    foreach ($table_key->column as $table_key_column) {
                        $col_name = (string) $table_key_column->attributes()->name;
                        $key_columns[] = $col_name;
                        // cache the primary key columns for this table
                        if ($table_key->getName() == 'primary_key') {
                            $info['tables'][$table_name]['primary_key'][] = $col_name;
                        }
                        if ($table_key->getName() == 'unique_key') {
                            $info['tables'][$table_name]['unique_key'][] = $col_name;
                        }
                    }
                    //end foreach
                }
                //end foreach
            }
            //end if
            //--        INDEXES        --//
            // check for any indexes that need creating
            if (!empty($table->indexes->index)) {
                foreach ($table->indexes->index as $table_index) {
                    // work out the columns in this index
                    $index_cols = array();
                    foreach ($table_index->column as $table_index_column) {
                        $index_cols[] = (string) $table_index_column->attributes()->name;
                    }
                    // work out the name of the index
                    $index_name = isset($table_index->attributes()->name) ? (string) $table_index->attributes()->name : reset($index_cols);
                    $index_type = isset($table_index->attributes()->type) ? (string) $table_index->attributes()->type : NULL;
                    $index_db_type = isset($table_index->attributes()->db) ? (string) $table_index->attributes()->db : NULL;
                    $index_info = array('name' => $index_name, 'columns' => $index_cols, 'type' => $index_type, 'db_type' => $index_db_type);
                    $info['tables'][$table_name]['indexes'][$index_name] = $index_info;
                }
                //end for
            }
            //end if
        }
        //end for
    }
    //end for
    foreach ($root->sequences->sequence as $sequence) {
        $sequence_name = (string) $sequence->attributes()->name;
        $info['sequences'][] = $sequence_name;
    }
    return $info;
}