[TASK] Harmonize coding style of if constructs in /typo3/sysext/cms/
[Packages/TYPO3.CMS.git] / typo3 / sysext / lowlevel / class.tx_lowlevel_cleaner_core.php
index 98b48f4..7b49852 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 /**
  * Core functions for cleaning and analysing
  *
- * $Id$
- *
- * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
- */
-/**
- * [CLASS/FUNCTION INDEX of SCRIPT]
- *
- *
- *
- *   71: class tx_lowlevel_cleaner_core extends t3lib_cli
- *   88:     function tx_lowlevel_cleaner_core()
- *
- *              SECTION: CLI functionality
- *  134:     function cli_main($argv)
- *  193:     function cli_referenceIndexCheck()
- *  228:     function cli_noExecutionCheck($matchString)
- *  251:     function cli_printInfo($header,$res)
- *
- *              SECTION: Page tree traversal
- *  331:     function genTree($rootID,$depth=1000,$echoLevel=0,$callBack='')
- *  369:     function genTree_traverse($rootID,$depth,$echoLevel=0,$callBack='',$versionSwapmode='',$rootIsVersion=0,$accumulatedPath='')
- *
- *              SECTION: Helper functions
- *  554:     function infoStr($rec)
- *
- * TOTAL FUNCTIONS: 8
- * (This index is automatically created/updated by the extension "extdeveval")
- *
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  */
 
 
 /**
  * Core functions for cleaning and analysing
  *
- * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage tx_lowlevel
  */
@@ -78,16 +51,18 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
 
        var $performanceStatistics = array();
 
+       protected $workspaceIndex = array();
+
 
        /**
         * Constructor
         *
         * @return      void
         */
-       function tx_lowlevel_cleaner_core()     {
+       function __construct() {
 
                        // Running parent class constructor
-               parent::t3lib_cli();
+               parent::__construct();
 
                $this->cleanerModules = (array)$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['lowlevel']['cleanerModules'];
 
@@ -96,16 +71,16 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                $this->cli_options[] = array('-v level', 'Verbosity level 0-3', "The value of level can be:\n  0 = all output\n  1 = info and greater (default)\n  2 = warnings and greater\n  3 = errors");
                $this->cli_options[] = array('--refindex mode', 'Mode for reference index handling for operations that require a clean reference index ("update"/"ignore")', 'Options are "check" (default), "update" and "ignore". By default, the reference index is checked before running analysis that require a clean index. If the check fails, the analysis is not run. You can choose to bypass this completely (using value "ignore") or ask to have the index updated right away before the analysis (using value "update")');
                $this->cli_options[] = array('--AUTOFIX [testName]', 'Repairs errors that can be automatically fixed.', 'Only add this option after having run the test without it so you know what will happen when you add this option! The optional parameter "[testName]" works for some tool keys to limit the fixing to a particular test.');
-               $this->cli_options[] = array('--dryrun', 'With --AUTOFIX it will only simulate a repair process','You may like to use this to see what the --AUTOFIX option will be doing. It will output the whole process like if a fix really occurred but nothing is in fact happening');
-               $this->cli_options[] = array('--YES', 'Implicit YES to all questions','Use this with EXTREME care. The option "-i" is not affected by this option.');
-               $this->cli_options[] = array('-i', 'Interactive','Will ask you before running the AUTOFIX on each element.');
-               $this->cli_options[] = array('--filterRegex expr', 'Define an expression for preg_match() that must match the element ID in order to auto repair it','The element ID is the string in quotation marks when the text \'Cleaning ... in "ELEMENT ID"\'. "expr" is the expression for preg_match(). To match for example "Nature3.JPG" and "Holiday3.JPG" you can use "/.*3.JPG/". To match for example "Image.jpg" and "Image.JPG" you can use "/.*.jpg/i". Try a --dryrun first to see what the matches are!');
+               $this->cli_options[] = array('--dryrun', 'With --AUTOFIX it will only simulate a repair process', 'You may like to use this to see what the --AUTOFIX option will be doing. It will output the whole process like if a fix really occurred but nothing is in fact happening');
+               $this->cli_options[] = array('--YES', 'Implicit YES to all questions', 'Use this with EXTREME care. The option "-i" is not affected by this option.');
+               $this->cli_options[] = array('-i', 'Interactive', 'Will ask you before running the AUTOFIX on each element.');
+               $this->cli_options[] = array('--filterRegex expr', 'Define an expression for preg_match() that must match the element ID in order to auto repair it', 'The element ID is the string in quotation marks when the text \'Cleaning ... in "ELEMENT ID"\'. "expr" is the expression for preg_match(). To match for example "Nature3.JPG" and "Holiday3.JPG" you can use "/.*3.JPG/". To match for example "Image.jpg" and "Image.JPG" you can use "/.*.jpg/i". Try a --dryrun first to see what the matches are!');
                $this->cli_options[] = array('--showhowto', 'Displays HOWTO file for cleaner script.');
 
                        // Setting help texts:
                $this->cli_help['name'] = 'lowlevel_cleaner -- Analysis and clean-up tools for TYPO3 installations';
                $this->cli_help['synopsis'] = 'toolkey ###OPTIONS###';
-               $this->cli_help['description'] = "Dispatches to various analysis and clean-up tools which can plug into the API of this script. Typically you can run tests that will take longer than the usual max execution time of PHP. Such tasks could be checking for orphan records in the page tree or flushing all published versions in the system. For the complete list of options, please explore each of the 'toolkey' keywords below:\n\n  ".implode("\n  ",array_keys($this->cleanerModules));
+               $this->cli_help['description'] = "Dispatches to various analysis and clean-up tools which can plug into the API of this script. Typically you can run tests that will take longer than the usual max execution time of PHP. Such tasks could be checking for orphan records in the page tree or flushing all published versions in the system. For the complete list of options, please explore each of the 'toolkey' keywords below:\n\n  ".implode("\n  ", array_keys($this->cleanerModules));
                $this->cli_help['examples'] = "/.../cli_dispatch.phpsh lowlevel_cleaner missing_files -s -r\nThis will show you missing files in the TYPO3 system and only report back if errors were found.";
                $this->cli_help['author'] = "Kasper Skaarhoej, (c) 2006";
        }
@@ -116,8 +91,6 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
 
 
 
-
-
        /**************************
         *
         * CLI functionality
@@ -137,15 +110,15 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                $GLOBALS['BE_USER']->setWorkspace(0);
 
                        // Print Howto:
-               if ($this->cli_isArg('--showhowto'))    {
+               if ($this->cli_isArg('--showhowto')) {
                        $howto = t3lib_div::getUrl(t3lib_extMgm::extPath('lowlevel').'HOWTO_clean_up_TYPO3_installations.txt');
-                       echo wordwrap($howto,120).chr(10);
+                       echo wordwrap($howto, 120).LF;
                        exit;
                }
 
                        // Print help
                $analysisType = (string)$this->cli_args['_DEFAULT'][1];
-               if (!$analysisType)     {
+               if (!$analysisType) {
                        $this->cli_validateArgs();
                        $this->cli_help();
                        exit;
@@ -154,21 +127,21 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                        // Analysis type:
                switch((string)$analysisType)    {
                        default:
-                               if (is_array($this->cleanerModules[$analysisType]))     {
-                                       $cleanerMode = &t3lib_div::getUserObj($this->cleanerModules[$analysisType][0]);
+                               if (is_array($this->cleanerModules[$analysisType])) {
+                                       $cleanerMode = t3lib_div::getUserObj($this->cleanerModules[$analysisType][0]);
                                        $cleanerMode->cli_validateArgs();
 
                                        if ($this->cli_isArg('-r'))     {       // Run it...
-                                               if (!$cleanerMode->checkRefIndex || $this->cli_referenceIndexCheck())   {
+                                               if (!$cleanerMode->checkRefIndex || $this->cli_referenceIndexCheck()) {
                                                        $res = $cleanerMode->main();
                                                        $this->cli_printInfo($analysisType, $res);
 
                                                                // Autofix...
-                                                       if ($this->cli_isArg('--AUTOFIX'))      {
-                                                               if ($this->cli_isArg('--YES') || $this->cli_keyboardInput_yes("\n\nNOW Running --AUTOFIX on result. OK?".($this->cli_isArg('--dryrun')?' (--dryrun simulation)':'')))   {
+                                                       if ($this->cli_isArg('--AUTOFIX')) {
+                                                               if ($this->cli_isArg('--YES') || $this->cli_keyboardInput_yes("\n\nNOW Running --AUTOFIX on result. OK?".($this->cli_isArg('--dryrun')?' (--dryrun simulation)':''))) {
                                                                        $cleanerMode->main_autofix($res);
                                                                } else {
-                                                                       $this->cli_echo("ABORTING AutoFix...\n",1);
+                                                                       $this->cli_echo("ABORTING AutoFix...\n", 1);
                                                                }
                                                        }
                                                }
@@ -177,7 +150,7 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                                                exit;
                                        }
                                } else {
-                                       $this->cli_echo("ERROR: Analysis Type '".$analysisType."' is unknown.\n",1);
+                                       $this->cli_echo("ERROR: Analysis Type '".$analysisType."' is unknown.\n", 1);
                                        exit;
                                }
                        break;
@@ -189,24 +162,24 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
         *
         * @return      boolean         TRUE if reference index was OK (either OK, updated or ignored)
         */
-       function cli_referenceIndexCheck()      {
+       function cli_referenceIndexCheck() {
 
                        // Reference index option:
                $refIndexMode = isset($this->cli_args['--refindex']) ? $this->cli_args['--refindex'][0] : 'check';
-               if (!t3lib_div::inList('update,ignore,check', $refIndexMode))   {
-                       $this->cli_echo("ERROR: Wrong value for --refindex argument.\n",1);
+               if (!t3lib_div::inList('update,ignore,check', $refIndexMode)) {
+                       $this->cli_echo("ERROR: Wrong value for --refindex argument.\n", 1);
                        exit;
                }
 
-               switch($refIndexMode)   {
+               switch($refIndexMode) {
                        case 'check':
                        case 'update':
                                $refIndexObj = t3lib_div::makeInstance('t3lib_refindex');
-                               list($headerContent,$bodyContent,$errorCount) = $refIndexObj->updateIndex($refIndexMode=='check',$this->cli_echo());
+                               list($headerContent, $bodyContent, $errorCount) = $refIndexObj->updateIndex($refIndexMode=='check', $this->cli_echo());
 
-                               if ($errorCount && $refIndexMode=='check')      {
+                               if ($errorCount && $refIndexMode=='check') {
                                        $ok = FALSE;
-                                       $this->cli_echo("ERROR: Reference Index Check failed! (run with '--refindex update' to fix)\n",1);
+                                       $this->cli_echo("ERROR: Reference Index Check failed! (run with '--refindex update' to fix)\n", 1);
                                } else {
                                        $ok = TRUE;
                                }
@@ -224,15 +197,15 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
         * @param       [type]          $matchString: ...
         * @return      string          If string, it's the reason for not executing. Returning FALSE means it should execute.
         */
-       function cli_noExecutionCheck($matchString)     {
+       function cli_noExecutionCheck($matchString) {
 
                        // Check for filter:
-               if ($this->cli_isArg('--filterRegex') && $regex = $this->cli_argValue('--filterRegex',0))       {
-                       if (!preg_match($regex,$matchString))   return 'BYPASS: Filter Regex "'.$regex.'" did not match string "'.$matchString.'"';
+               if ($this->cli_isArg('--filterRegex') && $regex = $this->cli_argValue('--filterRegex', 0)) {
+                       if (!preg_match($regex, $matchString))  return 'BYPASS: Filter Regex "'.$regex.'" did not match string "'.$matchString.'"';
                }
                        // Check for interactive mode
-               if ($this->cli_isArg('-i'))     {
-                       if (!$this->cli_keyboardInput_yes(' EXECUTE?')) {
+               if ($this->cli_isArg('-i')) {
+                       if (!$this->cli_keyboardInput_yes(' EXECUTE?')) {
                                return 'BYPASS...';
                        }
                }
@@ -247,9 +220,9 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
         * @param       array           Result array from an analyze function
         * @return      void            Outputs with echo - capture content with output buffer if needed.
         */
-       function cli_printInfo($header,$res)    {
+       function cli_printInfo($header, $res) {
 
-               $detailLevel = t3lib_div::intInRange($this->cli_isArg('-v') ? $this->cli_argValue('-v') : 1,0,3);
+               $detailLevel = t3lib_utility_Math::forceIntegerInRange($this->cli_isArg('-v') ? $this->cli_argValue('-v') : 1,0,3);
                $silent = !$this->cli_echo();
 
                $severity = array(
@@ -260,40 +233,40 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                );
 
                        // Header output:
-               if ($detailLevel <= 1)  {
+               if ($detailLevel <= 1) {
                        $this->cli_echo(
                                "*********************************************\n".
-                               $header."\n".
+                               $header.LF.
                                "*********************************************\n");
-                       $this->cli_echo(wordwrap(trim($res['message'])).chr(10).chr(10));
+                       $this->cli_echo(wordwrap(trim($res['message'])).LF.LF);
                }
 
                        // Traverse headers for output:
                if (is_array($res['headers'])) {
-                       foreach($res['headers'] as $key => $value)      {
+                       foreach($res['headers'] as $key => $value) {
 
-                               if ($detailLevel <= intval($value[2]))  {
+                               if ($detailLevel <= intval($value[2])) {
                                        if (is_array($res[$key]) && (count($res[$key]) || !$silent)) {
 
                                                        // Header and explanaion:
-                                               $this->cli_echo('---------------------------------------------'.chr(10),1);
-                                               $this->cli_echo('['.$header.']'.chr(10),1);
-                                               $this->cli_echo($value[0].' ['.$severity[$value[2]].']'.chr(10),1);
-                                               $this->cli_echo('---------------------------------------------'.chr(10),1);
-                                               if (trim($value[1]))    {
-                                                       $this->cli_echo('Explanation: '.wordwrap(trim($value[1])).chr(10).chr(10),1);
+                                               $this->cli_echo('---------------------------------------------'.LF, 1);
+                                               $this->cli_echo('['.$header.']'.LF, 1);
+                                               $this->cli_echo($value[0].' ['.$severity[$value[2]].']'.LF, 1);
+                                               $this->cli_echo('---------------------------------------------'.LF, 1);
+                                               if (trim($value[1])) {
+                                                       $this->cli_echo('Explanation: '.wordwrap(trim($value[1])).LF.LF, 1);
                                                }
                                        }
 
                                                // Content:
-                                       if (is_array($res[$key]))       {
-                                               if (count($res[$key]))  {
-                                                       if ($this->cli_echo('',1)) { print_r($res[$key]); }
+                                       if (is_array($res[$key])) {
+                                               if (count($res[$key])) {
+                                                       if ($this->cli_echo('', 1)) { print_r($res[$key]); }
                                                } else {
-                                                       $this->cli_echo('(None)'.chr(10).chr(10));
+                                                       $this->cli_echo('(None)'.LF.LF);
                                                }
                                        } else {
-                                               $this->cli_echo($res[$key].chr(10).chr(10));
+                                               $this->cli_echo($res[$key].LF.LF);
                                        }
                                }
                        }
@@ -327,12 +300,15 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
         * @param       string          Call back function (from this class or subclass)
         * @return      void
         */
-       function genTree($rootID,$depth=1000,$echoLevel=0,$callBack='') {
+       function genTree($rootID, $depth=1000, $echoLevel=0, $callBack='') {
 
-               $pt = t3lib_div::milliseconds();$this->performanceStatistics['genTree()']='';
+               $pt = t3lib_div::milliseconds();
+               $this->performanceStatistics['genTree()'] = '';
 
                        // Initialize:
-               $this->workspaceIndex = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,title','sys_workspace','1=1'.t3lib_BEfunc::deleteClause('sys_workspace'),'','','','uid');
+               if (t3lib_extMgm::isLoaded('workspaces')) {
+                       $this->workspaceIndex = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,title', 'sys_workspace', '1=1'.t3lib_BEfunc::deleteClause('sys_workspace'), '', '', '', 'uid');
+               }
                $this->workspaceIndex[-1] = TRUE;
                $this->workspaceIndex[0] = TRUE;
 
@@ -350,26 +326,28 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                );
 
                        // Start traversal:
-               $pt2 = t3lib_div::milliseconds();$this->performanceStatistics['genTree_traverse()']=''; $this->performanceStatistics['genTree_traverse():TraverseTables']='';
-               $this->genTree_traverse($rootID,$depth,$echoLevel,$callBack);
+               $pt2 = t3lib_div::milliseconds();
+               $this->performanceStatistics['genTree_traverse()'] = '';
+               $this->performanceStatistics['genTree_traverse():TraverseTables'] = '';
+               $this->genTree_traverse($rootID, $depth, $echoLevel, $callBack);
                $this->performanceStatistics['genTree_traverse()'] = t3lib_div::milliseconds()-$pt2;
 
                        // Sort recStats (for diff'able displays)
-               foreach($this->recStats as $kk => $vv)  {
-                       foreach($this->recStats[$kk] as $tables => $recArrays)  {
+               foreach($this->recStats as $kk => $vv) {
+                       foreach($this->recStats[$kk] as $tables => $recArrays) {
                                ksort($this->recStats[$kk][$tables]);
                        }
                        ksort($this->recStats[$kk]);
                }
 
-               if ($echoLevel>0)       echo chr(10).chr(10);
+               if ($echoLevel>0)       echo LF.LF;
 
 
                        // Processing performance statistics:
                $this->performanceStatistics['genTree()'] = t3lib_div::milliseconds()-$pt;
 
                        // Count records:
-               foreach($GLOBALS['TCA'] as $tableName => $cfg)  {
+               foreach($GLOBALS['TCA'] as $tableName => $cfg) {
                                // Select all records belonging to page:
                        $resSub = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
                                'count(*)',
@@ -378,14 +356,14 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                        );
                        $countRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resSub);
                        $this->performanceStatistics['MySQL_count'][$tableName]=$countRow['count(*)'];
-                       $this->performanceStatistics['CSV'].=chr(10).$tableName.','.
+                       $this->performanceStatistics['CSV'].=LF.$tableName.','.
                                                                $this->performanceStatistics['genTree_traverse():TraverseTables:']['MySQL'][$tableName].','.
                                                                $this->performanceStatistics['genTree_traverse():TraverseTables:']['Proc'][$tableName].','.
                                                                $this->performanceStatistics['MySQL_count'][$tableName];
                }
 
                $this->performanceStatistics['recStats_size']['(ALL)']=strlen(serialize($this->recStats));
-               foreach($this->recStats as $key => $arrcontent) {
+               foreach($this->recStats as $key => $arrcontent) {
                        $this->performanceStatistics['recStats_size'][$key]=strlen(serialize($arrcontent));
                }
        }
@@ -403,19 +381,19 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
         * @return      void
         * @access private
         */
-       function genTree_traverse($rootID,$depth,$echoLevel=0,$callBack='',$versionSwapmode='',$rootIsVersion=0,$accumulatedPath='')    {
+       function genTree_traverse($rootID, $depth, $echoLevel=0, $callBack='', $versionSwapmode='', $rootIsVersion=0, $accumulatedPath='') {
 
                        // Register page:
                $this->recStats['all']['pages'][$rootID] = $rootID;
-               $pageRecord = t3lib_BEfunc::getRecordRaw('pages','uid='.intval($rootID),'deleted,title,t3ver_count,t3ver_wsid');
+               $pageRecord = t3lib_BEfunc::getRecordRaw('pages', 'uid='.intval($rootID), 'deleted,title,t3ver_count,t3ver_wsid');
                $accumulatedPath.='/'.$pageRecord['title'];
 
                        // Register if page is deleted:
-               if ($pageRecord['deleted'])     {
+               if ($pageRecord['deleted']) {
                        $this->recStats['deleted']['pages'][$rootID] = $rootID;
                }
                        // If rootIsVersion is set it means that the input rootID is that of a version of a page. See below where the recursive call is made.
-               if ($rootIsVersion)     {
+               if ($rootIsVersion) {
                        $this->recStats['versions']['pages'][$rootID] = $rootID;
                        if ($pageRecord['t3ver_count']>=1 && $pageRecord['t3ver_wsid']==0)      {       // If it has been published and is in archive now...
                                $this->recStats['versions_published']['pages'][$rootID] = $rootID;
@@ -432,24 +410,23 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                }
 
                if ($echoLevel>0)
-                       echo chr(10).$accumulatedPath.' ['.$rootID.']'.
+                       echo LF.$accumulatedPath.' ['.$rootID.']'.
                                ($pageRecord['deleted'] ? ' (DELETED)':'').
-                               ($this->recStats['versions_published']['pages'][$rootID] ? ' (PUBLISHED)':'')
-                               ;
+                               ($this->recStats['versions_published']['pages'][$rootID] ? ' (PUBLISHED)':'');
                if ($echoLevel>1 && $this->recStats['versions_lost_workspace']['pages'][$rootID])
-                       echo chr(10).'  ERROR! This version belongs to non-existing workspace ('.$pageRecord['t3ver_wsid'].')!';
+                       echo LF.'       ERROR! This version belongs to non-existing workspace ('.$pageRecord['t3ver_wsid'].')!';
                if ($echoLevel>1 && $this->recStats['versions_inside_versioned_page']['pages'][$rootID])
-                       echo chr(10).'  WARNING! This version is inside an already versioned page or branch!';
+                       echo LF.'       WARNING! This version is inside an already versioned page or branch!';
 
                        // Call back:
-               if ($callBack)  {
-                       $this->$callBack('pages',$rootID,$echoLevel,$versionSwapmode,$rootIsVersion);
+               if ($callBack) {
+                       $this->$callBack('pages', $rootID, $echoLevel, $versionSwapmode, $rootIsVersion);
                }
 
                $pt3 = t3lib_div::milliseconds();
 
                        // Traverse tables of records that belongs to page:
-               foreach($GLOBALS['TCA'] as $tableName => $cfg)  {
+               foreach($GLOBALS['TCA'] as $tableName => $cfg) {
                        if ($tableName!='pages') {
 
                                        // Select all records belonging to page:
@@ -465,23 +442,23 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
 
                                $pt5=t3lib_div::milliseconds();
                                $count = $GLOBALS['TYPO3_DB']->sql_num_rows($resSub);
-                               if ($count)     {
-                                       if ($echoLevel==2)      echo chr(10).'  \-'.$tableName.' ('.$count.')';
+                               if ($count) {
+                                       if ($echoLevel==2)      echo LF.'       \-'.$tableName.' ('.$count.')';
                                }
 
-                               while ($rowSub = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resSub))        {
-                                       if ($echoLevel==3)      echo chr(10).'  \-'.$tableName.':'.$rowSub['uid'];
+                               while ($rowSub = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resSub)) {
+                                       if ($echoLevel==3)      echo LF.'       \-'.$tableName.':'.$rowSub['uid'];
 
                                                // If the rootID represents an "element" or "page" version type, we must check if the record from this table is allowed to belong to this:
-                                       if ($versionSwapmode=='SWAPMODE:-1' || ($versionSwapmode=='SWAPMODE:0' && !$GLOBALS['TCA'][$tableName]['ctrl']['versioning_followPages']))      {
+                                       if ($versionSwapmode=='SWAPMODE:-1' || ($versionSwapmode=='SWAPMODE:0' && !$GLOBALS['TCA'][$tableName]['ctrl']['versioning_followPages'])) {
                                                        // This is illegal records under a versioned page - therefore not registered in $this->recStats['all'] so they should be orphaned:
                                                $this->recStats['illegal_record_under_versioned_page'][$tableName][$rowSub['uid']] = $rowSub['uid'];
-                                               if ($echoLevel>1)       echo chr(10).'          ERROR! Illegal record ('.$tableName.':'.$rowSub['uid'].') under versioned page!';
+                                               if ($echoLevel>1)       echo LF.'               ERROR! Illegal record ('.$tableName.':'.$rowSub['uid'].') under versioned page!';
                                        } else {
                                                $this->recStats['all'][$tableName][$rowSub['uid']] = $rowSub['uid'];
 
                                                        // Register deleted:
-                                               if ($GLOBALS['TCA'][$tableName]['ctrl']['delete'] && $rowSub[$GLOBALS['TCA'][$tableName]['ctrl']['delete']])    {
+                                               if ($GLOBALS['TCA'][$tableName]['ctrl']['delete'] && $rowSub[$GLOBALS['TCA'][$tableName]['ctrl']['delete']]) {
                                                        $this->recStats['deleted'][$tableName][$rowSub['uid']] = $rowSub['uid'];
                                                        if ($echoLevel==3)      echo ' (DELETED)';
                                                }
@@ -489,29 +466,29 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                                                        // Check location of records regarding tree root:
                                                if (!$GLOBALS['TCA'][$tableName]['ctrl']['rootLevel'] && $rootID==0) {
                                                        $this->recStats['misplaced_at_rootlevel'][$tableName][$rowSub['uid']] = $rowSub['uid'];
-                                                       if ($echoLevel>1)       echo chr(10).'          ERROR! Misplaced record ('.$tableName.':'.$rowSub['uid'].') on rootlevel!';
+                                                       if ($echoLevel>1)       echo LF.'               ERROR! Misplaced record ('.$tableName.':'.$rowSub['uid'].') on rootlevel!';
                                                }
                                                if ($GLOBALS['TCA'][$tableName]['ctrl']['rootLevel']==1 && $rootID>0) {
                                                        $this->recStats['misplaced_inside_tree'][$tableName][$rowSub['uid']] = $rowSub['uid'];
-                                                       if ($echoLevel>1)       echo chr(10).'          ERROR! Misplaced record ('.$tableName.':'.$rowSub['uid'].') inside page tree!';
+                                                       if ($echoLevel>1)       echo LF.'               ERROR! Misplaced record ('.$tableName.':'.$rowSub['uid'].') inside page tree!';
                                                }
 
                                                        // Traverse plugins:
-                                               if ($callBack)  {
-                                                       $this->$callBack($tableName,$rowSub['uid'],$echoLevel,$versionSwapmode,$rootIsVersion);
+                                               if ($callBack) {
+                                                       $this->$callBack($tableName, $rowSub['uid'], $echoLevel, $versionSwapmode, $rootIsVersion);
                                                }
 
                                                        // Add any versions of those records:
-                                               if ($this->genTree_traverseVersions)    {
+                                               if ($this->genTree_traverseVersions) {
                                                        $versions = t3lib_BEfunc::selectVersionsOfRecord($tableName, $rowSub['uid'], 'uid,t3ver_wsid,t3ver_count'.($GLOBALS['TCA'][$tableName]['ctrl']['delete']?','.$GLOBALS['TCA'][$tableName]['ctrl']['delete']:''), 0, TRUE);
-                                                       if (is_array($versions))        {
-                                                               foreach($versions as $verRec)   {
-                                                                       if (!$verRec['_CURRENT_VERSION'])       {
-                                                                               if ($echoLevel==3)      echo chr(10).'          \-[#OFFLINE VERSION: WS#'.$verRec['t3ver_wsid'].'/Cnt:'.$verRec['t3ver_count'].'] '.$tableName.':'.$verRec['uid'].')';
+                                                       if (is_array($versions)) {
+                                                               foreach($versions as $verRec) {
+                                                                       if (!$verRec['_CURRENT_VERSION']) {
+                                                                               if ($echoLevel==3)      echo LF.'               \-[#OFFLINE VERSION: WS#'.$verRec['t3ver_wsid'].'/Cnt:'.$verRec['t3ver_count'].'] '.$tableName.':'.$verRec['uid'].')';
                                                                                $this->recStats['all'][$tableName][$verRec['uid']] = $verRec['uid'];
 
                                                                                        // Register deleted:
-                                                                               if ($GLOBALS['TCA'][$tableName]['ctrl']['delete'] && $verRec[$GLOBALS['TCA'][$tableName]['ctrl']['delete']])    {
+                                                                               if ($GLOBALS['TCA'][$tableName]['ctrl']['delete'] && $verRec[$GLOBALS['TCA'][$tableName]['ctrl']['delete']]) {
                                                                                        $this->recStats['deleted'][$tableName][$verRec['uid']] = $verRec['uid'];
                                                                                        if ($echoLevel==3)      echo ' (DELETED)';
                                                                                }
@@ -522,21 +499,21 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                                                                                        $this->recStats['versions_published'][$tableName][$verRec['uid']] = $verRec['uid'];
                                                                                        if ($echoLevel==3)      echo ' (PUBLISHED)';
                                                                                }
-                                                                               if ($verRec['t3ver_wsid']==0)   {
+                                                                               if ($verRec['t3ver_wsid']==0) {
                                                                                        $this->recStats['versions_liveWS'][$tableName][$verRec['uid']] = $verRec['uid'];
                                                                                }
-                                                                               if (!isset($this->workspaceIndex[$verRec['t3ver_wsid']]))       {
+                                                                               if (!isset($this->workspaceIndex[$verRec['t3ver_wsid']])) {
                                                                                        $this->recStats['versions_lost_workspace'][$tableName][$verRec['uid']] = $verRec['uid'];
-                                                                                       if ($echoLevel>1)       echo chr(10).'          ERROR! Version ('.$tableName.':'.$verRec['uid'].') belongs to non-existing workspace ('.$verRec['t3ver_wsid'].')!';
+                                                                                       if ($echoLevel>1)       echo LF.'               ERROR! Version ('.$tableName.':'.$verRec['uid'].') belongs to non-existing workspace ('.$verRec['t3ver_wsid'].')!';
                                                                                }
                                                                                if ($versionSwapmode)   {       // In case we are inside a versioned branch, there should not exists versions inside that "branch".
                                                                                        $this->recStats['versions_inside_versioned_page'][$tableName][$verRec['uid']] = $verRec['uid'];
-                                                                                       if ($echoLevel>1)       echo chr(10).'          ERROR! This version ('.$tableName.':'.$verRec['uid'].') is inside an already versioned page or branch!';
+                                                                                       if ($echoLevel>1)       echo LF.'               ERROR! This version ('.$tableName.':'.$verRec['uid'].') is inside an already versioned page or branch!';
                                                                                }
 
                                                                                        // Traverse plugins:
-                                                                               if ($callBack)  {
-                                                                                       $this->$callBack($tableName,$verRec['uid'],$echoLevel,$versionSwapmode,$rootIsVersion);
+                                                                               if ($callBack) {
+                                                                                       $this->$callBack($tableName, $verRec['uid'], $echoLevel, $versionSwapmode, $rootIsVersion);
                                                                                }
                                                                        }
                                                                }
@@ -556,8 +533,8 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                $this->performanceStatistics['genTree_traverse():TraverseTables']+= t3lib_div::milliseconds()-$pt3;
 
                        // Find subpages to root ID and traverse (only when rootID is not a version or is a branch-version):
-               if (!$versionSwapmode || $versionSwapmode=='SWAPMODE:1')        {
-                       if ($depth>0)   {
+               if (!$versionSwapmode || $versionSwapmode=='SWAPMODE:1') {
+                       if ($depth>0) {
                                $depth--;
                                $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
                                        'uid',
@@ -567,18 +544,18 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                                        '',
                                        'sorting'
                                );
-                               while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
-                                       $this->genTree_traverse($row['uid'],$depth,$echoLevel,$callBack,$versionSwapmode,0,$accumulatedPath);
+                               while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+                                       $this->genTree_traverse($row['uid'], $depth, $echoLevel, $callBack, $versionSwapmode, 0, $accumulatedPath);
                                }
                        }
 
                                // Add any versions of pages
-                       if ($rootID>0 && $this->genTree_traverseVersions)       {
+                       if ($rootID>0 && $this->genTree_traverseVersions) {
                                $versions = t3lib_BEfunc::selectVersionsOfRecord('pages', $rootID, 'uid,t3ver_oid,t3ver_wsid,t3ver_count,t3ver_swapmode', 0, TRUE);
-                               if (is_array($versions))        {
-                                       foreach($versions as $verRec)   {
-                                               if (!$verRec['_CURRENT_VERSION'])       {
-                                                       $this->genTree_traverse($verRec['uid'],$depth,$echoLevel,$callBack,'SWAPMODE:'.t3lib_div::intInRange($verRec['t3ver_swapmode'],-1,1),$versionSwapmode?2:1,$accumulatedPath.' [#OFFLINE VERSION: WS#'.$verRec['t3ver_wsid'].'/Cnt:'.$verRec['t3ver_count'].']');
+                               if (is_array($versions)) {
+                                       foreach($versions as $verRec) {
+                                               if (!$verRec['_CURRENT_VERSION']) {
+                                                       $this->genTree_traverse($verRec['uid'], $depth, $echoLevel, $callBack, 'SWAPMODE:'.t3lib_utility_Math::forceIntegerInRange($verRec['t3ver_swapmode'], -1, 1), $versionSwapmode?2:1, $accumulatedPath.' [#OFFLINE VERSION: WS#'.$verRec['t3ver_wsid'].'/Cnt:'.$verRec['t3ver_count'].']');
                                                }
                                        }
                                }
@@ -605,13 +582,8 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
         * @param       array           Input record from sys_refindex
         * @return      string          String identifying the main record of the reference
         */
-       function infoStr($rec)  {
+       function infoStr($rec) {
                return $rec['tablename'].':'.$rec['recuid'].':'.$rec['field'].':'.$rec['flexpointer'].':'.$rec['softref_key'].($rec['deleted'] ? ' (DELETED)':'');
        }
 }
-
-if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/lowlevel/class.tx_lowlevel_cleaner.php'])     {
-       include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/lowlevel/class.tx_lowlevel_cleaner.php']);
-}
-
 ?>
\ No newline at end of file