/**
* Finds an existing asset matching the exact type with the metadata or attribute value supplied
*
* @return void
* @access public
*/
function findAsset($root_asset_id, $asset_type_code, array $search)
{
    // Begin uberquery!
    $db = MatrixDAL::getDb();
    $search_type_attribute = isset($search['attribute']);
    $field_name = '';
    $field_value = '';
    if ($search_type_attribute) {
        $field_name = $search['attribute']['field'];
        $field_value = $search['attribute']['value'];
    } else {
        $field_name = $search['metadata']['field'];
        $field_value = $search['metadata']['value'];
    }
    $tree_id = '';
    // Grab a single tree ID so we can search our entire root asset
    $sql = 'SELECT t.treeid FROM sq_ast_lnk_tree t, sq_ast_lnk l WHERE l.linkid = t.linkid AND l.minorid = :root_asset_id LIMIT 1';
    try {
        $query = MatrixDAL::preparePdoQuery($sql);
        MatrixDAL::bindValueToPdo($query, 'root_asset_id', $root_asset_id);
        $tree_id = MatrixDAL::executePdoOne($query);
    } catch (Exception $e) {
        throw new Exception('Unable to search for an existing ' . $asset_type_code . ' asset: ' . $e->getMessage());
    }
    if ($tree_id == '') {
        return array();
    }
    // Query portion for restricting by attribute
    $attribute_sql_from = 'sq_ast_attr r, sq_ast_attr_val v ';
    // Query portion for restricting by metadata field value
    $metadata_sql_from = 'sq_ast_mdata_val m ';
    $sql = 'SELECT a.assetid, a.name ' . 'FROM sq_ast a, sq_ast_lnk l, sq_ast_lnk_tree t, ' . ($search_type_attribute ? $attribute_sql_from : $metadata_sql_from) . 'WHERE t.treeid LIKE :tree_id ' . 'AND l.linkid = t.linkid AND a.assetid = l.minorid ';
    if (!empty($asset_type_code)) {
        $sql .= 'AND a.type_code = :type_code ';
    }
    if ($search_type_attribute) {
        $sql .= ' AND v.assetid = a.assetid AND r.name = :field_name AND v.attrid = r.attrid AND v.custom_val = :field_val';
    } else {
        $sql .= ' AND m.assetid = a.assetid AND m.fieldid = :field_name AND m.value = :field_val';
    }
    try {
        $query = MatrixDAL::preparePdoQuery($sql);
        MatrixDAL::bindValueToPdo($query, 'tree_id', $tree_id . '%');
        MatrixDAL::bindValueToPdo($query, 'field_name', $field_name);
        MatrixDAL::bindValueToPdo($query, 'field_val', $field_value);
        if (!empty($asset_type_code)) {
            MatrixDAL::bindValueToPdo($query, 'type_code', $asset_type_code);
        }
        $matching_assets = MatrixDAL::executePdoAssoc($query, 0);
    } catch (Exception $e) {
        throw new Exception('Unable to search for an existing ' . $asset_type_code . ' asset: ' . $e->getMessage());
    }
    return $matching_assets;
}
         $is_matrix_url = FALSE;
         foreach ($root_urls as $root_url) {
             if (strpos($url, $root_url . '/') === 0 || $url === $root_url) {
                 $is_matrix_url = TRUE;
                 break;
             }
         }
         // if it's not a Matrix URL, no need to show warning
         if ($is_matrix_url) {
             // if it's one of special url, no need to show warning
             if (strpos($url, '__data') === FALSE && strpos($url, '__lib') === FALSE && strpos($url, '__fudge') === FALSE) {
                 $url_asset = $GLOBALS['SQ_SYSTEM']->am->getAssetFromURL($protocol, $url, TRUE, TRUE);
                 $count_query = 'SELECT count(*) FROM sq_ast_lookup_remap WHERE url = :url ';
                 $count_result = MatrixDAL::preparePdoQuery($count_query);
                 MatrixDAL::bindValueToPdo($count_result, 'url', $url_info['remap_url']);
                 $remap_url = MatrixDAL::executePdoOne($count_result);
                 // if the new url is not an valid asset url, neither another redirect url, show warning
                 if (empty($url_asset) && empty($remap_url)) {
                     $affected_result[] = $url_info;
                 }
                 $GLOBALS['SQ_SYSTEM']->am->forgetAsset($url_asset);
                 unset($url_asset);
             }
         }
     }
 }
 if (getCLIArg('execute') && !empty($affected_result)) {
     // delete them
     $count = deleteRemaps($affected_result);
     echo $count . " remaps deleted\n";
 } else {
Пример #3
0
if (!empty($purge_rootnode)) {
    // do some checking to make sure there is a link to the trash folder
    $trash_folder = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('trash_folder');
    $db = $GLOBALS['SQ_SYSTEM']->db;
    $sql = 'select
				linkid
			from
				sq_ast_lnk
			where
				minorid = :root_node
				and
				majorid = :trash_assetid';
    $query = MatrixDAL::preparePdoQuery($sql);
    MatrixDAL::bindValueToPdo($query, 'root_node', $purge_rootnode);
    MatrixDAL::bindValueToPdo($query, 'trash_assetid', $trash_folder->id);
    $linkid = MatrixDAL::executePdoOne($query);
    if (!empty($linkid)) {
        // purge trash hipo will know what to do
        $vars['purge_root_linkid'] = $linkid;
    } else {
        printStdErr("Purge root node assetid id #" . $purge_rootnode . " not found\n");
        exit(1);
    }
}
$hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
$errors = $hh->freestyleHipo('hipo_job_purge_trash', $vars);
if (!empty($errors)) {
    $error_msg = '';
    foreach ($errors as $error) {
        $error_msg .= ' * ' . $error['message'];
    }
$am =& $GLOBALS['SQ_SYSTEM']->am;
$db = NULL;
// PHP 5
if (version_compare(phpversion(), 5) >= 0) {
    $db = MatrixDAL::getDb();
} else {
    $db =& $GLOBALS['SQ_SYSTEM']->db;
}
// get the attribute id
$select_attribute = 'select attrid from sq_ast_attr where type_code = \'page_asset_listing\' and name = \'metadata_sort_type\'';
$attribute_id = NULL;
// PHP 5
if (version_compare(phpversion(), 5) >= 0) {
    $query = $db->prepare($select_attribute);
    try {
        $attribute_id = MatrixDAL::executePdoOne($query);
    } catch (Exception $e) {
        throw new Exception($e . getMessage());
    }
    //end
} else {
    $attribute_id = $db->getOne($select_attribute);
    assert_valid_db_result($attribute_id);
}
// if the attribute is not found exit
if (empty($attribute_id)) {
    echo 'The attribute "metadata_sort_type" for "page_asset_listing" does not exists';
    exit;
}
// get all the page_asset_listings
$assets_id = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids('page_asset_listing', TRUE);
/**
* 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;
}
/**
 * Insert a file record info to sq_file_vers_file table if one does not exist
 *
 * @param File_Versioning $file_versioning	the File_Versioning object
 * @param string $fileid	the fileid of the file to be inserted
 * @param string $rep_file	the repository file path of the file
 * @see add() in file_versioning.inc
 */
function _insertFileVersFileInfo($file_versioning, $fileid, $rep_file)
{
    $sql = 'SELECT COUNT(*)
			FROM sq_file_vers_file
			WHERE fileid = :fileid';
    $fileid_count = 0;
    try {
        $query = MatrixDAL::preparePdoQuery($sql);
        MatrixDAL::bindValueToPdo($query, 'fileid', $fileid);
        $fileid_count = MatrixDAL::executePdoOne($query);
    } catch (Exception $e) {
        echo "ERROR: " . $e->getMessage() . "\n";
        return;
    }
    //the record info already exists, return without doing anything
    if ($fileid_count != 0) {
        return;
    }
    $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
    $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
    $sql = 'INSERT INTO sq_file_vers_file (fileid, path, filename)
			VALUES (:fileid, :path, :filename)';
    try {
        $query = MatrixDAL::preparePdoQuery($sql);
        MatrixDAL::bindValueToPdo($query, 'fileid', $fileid);
        MatrixDAL::bindValueToPdo($query, 'path', dirname($rep_file));
        MatrixDAL::bindValueToPdo($query, 'filename', basename($rep_file));
        MatrixDAL::execPdoQuery($query);
        $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
        $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
    } catch (Exception $e) {
        echo "ERROR: " . $e->getMessage() . "\n";
        $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
        $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
    }
}
Пример #7
0
    MatrixDAL::dbConnect($db_conf['dbslon'], 'dbslon');
    $db = MatrixDAL::getDb('dbslon');
    $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
    $start_time = time();
    $query = MatrixDAL::preparePdoQuery($slon_schema_query);
    try {
        $slon_schema = MatrixDAL::executePdoOne($query);
    } catch (Exception $e) {
        $slon_schema = '';
        $return_code = '500';
    }
    if (!empty($slon_schema)) {
        $output .= $slon_schema . ':';
        $query = MatrixDAL::preparePdoQuery(str_replace('{SLON_SCHEMA}', $slon_schema, $slon_schema_lag_query));
        try {
            $lag = MatrixDAL::executePdoOne($query);
        } catch (Exception $e) {
            $lag = '-1';
            $return_code = '500';
        }
    } else {
        $output .= '0:';
    }
    $output .= $lag . ':' . ceil(time() - $start_time) . "\n";
    $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
}
if ($return_code == '200') {
    header('HTTP/1.0 200 OK');
} else {
    header('HTTP/1.0 ' . $return_code . ' Internal Server Error');
}