*/ if (getCLIArg('redirect_chain')) { echo "\n## Redirect Chain ##\n"; $db_type = _getDbType(); $except_clause = 'EXCEPT'; if ($db_type === 'oci') { $except_clause = 'MINUS'; } // find out all long redirects with magic query $sql = '(SELECT a.* FROM sq_ast_lookup_remap a, sq_ast_lookup_remap b WHERE a.url = b.remap_url) UNION ALL (SELECT c.* FROM sq_ast_lookup_remap c, sq_ast_lookup_remap d WHERE c.remap_url = d.url ' . $except_clause . ' SELECT c.* FROM sq_ast_lookup_remap c, sq_ast_lookup_remap d WHERE c.url = d.remap_url )'; $query = MatrixDAL::preparePdoQuery($sql); $result = MatrixDAL::executePdoAll($query); $sorted_result = array(); // now we have to sort them nicely to report while (count($result) > 0) { // grab a random element from remaining result $url_info = array_shift($result); // find chained elements redirecting from it, i.e trace in normal redirect order. e.g A->B->C->D, starting from B, it will find C and D $redirects_chain_from = recursiveTrace($url_info['remap_url'], $result, TRUE); // find chained elements redirecting to it, i.e trace in reversed order. e.g A->B->C->D, starting from B, it will find A $redirects_chain_to = recursiveTrace($url_info['url'], $result, FALSE); // add the current element to it array_push($redirects_chain_to, $url_info); // now we found a complete chain of redirects... $sorted_result[] = array_merge($redirects_chain_to, $redirects_chain_from); } if (getCLIArg('execute') && !empty($sorted_result)) {
/** * Get the next sort order for the next asset under a parent asset * * @param $parent_assetid The parent asset to get its children' next sort order * @return int */ function getNextSortOrder($parent_assetid) { $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db'); $sql = 'SELECT COUNT(*) as count, MAX(sort_order) as max FROM sq_ast_lnk WHERE majorid = :majorid'; try { $query = MatrixDAL::preparePdoQuery($sql); MatrixDAL::bindValueToPdo($query, 'majorid', $parent_assetid); $result = MatrixDAL::executePdoAll($query); $row = $result[0]; unset($result); } catch (Exception $e) { throw new Exception("Unable to get the last sort order of the parent asset #{$parent_assetid} , due to database error: " . $e->getMessage()); } $next_sort_order = $row['count'] > 0 ? max($row['count'], $row['max'] + 1) : 0; $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection(); return $next_sort_order; }