[TASK] Remove function index
[Packages/TYPO3.CMS.git] / typo3 / sysext / lowlevel / class.tx_lowlevel_cleaner_core.php
index 85ada4a..2f4db04 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2005 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>
+ * @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")
- *
- */
-
-
-require_once(PATH_t3lib.'class.t3lib_admin.php');
-require_once(PATH_t3lib.'class.t3lib_cli.php');
-
 
 
 /**
  * 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
  */
@@ -81,16 +49,20 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
        var $pagetreePlugins = array();
        var $cleanerModules = array();
 
+       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'];
 
@@ -142,7 +114,7 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                        // Print Howto:
                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;
                }
 
@@ -158,7 +130,7 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                switch((string)$analysisType)    {
                        default:
                                if (is_array($this->cleanerModules[$analysisType]))     {
-                                       $cleanerMode = &t3lib_div::getUserObj($this->cleanerModules[$analysisType][0]);
+                                       $cleanerMode = t3lib_div::getUserObj($this->cleanerModules[$analysisType][0]);
                                        $cleanerMode->cli_validateArgs();
 
                                        if ($this->cli_isArg('-r'))     {       // Run it...
@@ -266,9 +238,9 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                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:
@@ -279,12 +251,12 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                                        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);
+                                               $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])).chr(10).chr(10),1);
+                                                       $this->cli_echo('Explanation: '.wordwrap(trim($value[1])).LF.LF,1);
                                                }
                                        }
 
@@ -293,10 +265,10 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                                                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);
                                        }
                                }
                        }
@@ -332,8 +304,13 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
         */
        function genTree($rootID,$depth=1000,$echoLevel=0,$callBack='') {
 
+               $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;
 
@@ -351,8 +328,12 @@ 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);
-               
+               $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)  {
@@ -361,7 +342,32 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                        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)  {
+                               // Select all records belonging to page:
+                       $resSub = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
+                               'count(*)',
+                               $tableName,
+                               ''
+                       );
+                       $countRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resSub);
+                       $this->performanceStatistics['MySQL_count'][$tableName]=$countRow['count(*)'];
+                       $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) {
+                       $this->performanceStatistics['recStats_size'][$key]=strlen(serialize($arrcontent));
+               }
        }
 
        /**
@@ -406,45 +412,51 @@ 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)':'')
                                ;
                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);
                }
 
+               $pt3 = t3lib_div::milliseconds();
+
                        // Traverse tables of records that belongs to page:
                foreach($GLOBALS['TCA'] as $tableName => $cfg)  {
                        if ($tableName!='pages') {
 
                                        // Select all records belonging to page:
+                               $pt4=t3lib_div::milliseconds();
                                $resSub = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
                                        'uid'.($GLOBALS['TCA'][$tableName]['ctrl']['delete']?','.$GLOBALS['TCA'][$tableName]['ctrl']['delete']:''),
                                        $tableName,
                                        'pid='.intval($rootID).
                                                ($this->genTree_traverseDeleted ? '' : t3lib_BEfunc::deleteClause($tableName))
                                );
+                               $this->performanceStatistics['genTree_traverse():TraverseTables:']['MySQL']['(ALL)']+= t3lib_div::milliseconds()-$pt4;
+                               $this->performanceStatistics['genTree_traverse():TraverseTables:']['MySQL'][$tableName]+= t3lib_div::milliseconds()-$pt4;
 
+                               $pt5=t3lib_div::milliseconds();
                                $count = $GLOBALS['TYPO3_DB']->sql_num_rows($resSub);
                                if ($count)     {
-                                       if ($echoLevel==2)      echo chr(10).'  \-'.$tableName.' ('.$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'];
+                                       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']))      {
                                                        // 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'];
 
@@ -457,11 +469,11 @@ 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:
@@ -475,7 +487,7 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                                                        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 ($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:
@@ -495,11 +507,11 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                                                                                }
                                                                                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:
@@ -513,10 +525,15 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
                                                }
                                        }
                                }
+
+                               $this->performanceStatistics['genTree_traverse():TraverseTables:']['Proc']['(ALL)']+= t3lib_div::milliseconds()-$pt5;
+                               $this->performanceStatistics['genTree_traverse():TraverseTables:']['Proc'][$tableName]+= t3lib_div::milliseconds()-$pt5;
+
                        }
                }
                unset($resSub);
                unset($rowSub);
+               $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')        {
@@ -573,7 +590,8 @@ class tx_lowlevel_cleaner_core extends t3lib_cli {
        }
 }
 
-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']);
+if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/lowlevel/class.tx_lowlevel_cleaner.php'])) {
+       include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/lowlevel/class.tx_lowlevel_cleaner.php']);
 }
-?>
+
+?>
\ No newline at end of file