⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class.tx_lowlevel_cleaner_core.php

📁 Typo3, 开源里边最强大的
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/****************************************************************  Copyright notice**  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)*  All rights reserved**  This script is part of the TYPO3 project. The TYPO3 project is*  free software; you can redistribute it and/or modify*  it under the terms of the GNU General Public License as published by*  the Free Software Foundation; either version 2 of the License, or*  (at your option) any later version.**  The GNU General Public License can be found at*  http://www.gnu.org/copyleft/gpl.html.*  A copy is found in the textfile GPL.txt and important notices to the license*  from the author is found in LICENSE.txt distributed with these scripts.***  This script is distributed in the hope that it will be useful,*  but WITHOUT ANY WARRANTY; without even the implied warranty of*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the*  GNU General Public License for more details.**  This copyright notice MUST APPEAR in all copies of the script!***************************************************************//** * Core functions for cleaning and analysing * * @author	Kasper Sk錼h鴍 <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錼h鴍 <kasperYYYY@typo3.com> * @package TYPO3 * @subpackage tx_lowlevel */class tx_lowlevel_cleaner_core extends t3lib_cli {	var $genTree_traverseDeleted = TRUE;	var $genTree_traverseVersions = TRUE;	var $label_infoString = 'The list of records is organized as [table]:[uid]:[field]:[flexpointer]:[softref_key]';	var $pagetreePlugins = array();	var $cleanerModules = array();	/**	 * Constructor	 *	 * @return	void	 */	function tx_lowlevel_cleaner_core()	{			// Running parent class constructor		parent::t3lib_cli();		$this->cleanerModules = (array)$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['lowlevel']['cleanerModules'];			// Adding options to help archive:		$this->cli_options[] = array('-r', 'Execute this tool, otherwise help is shown');		$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', '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!');		$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['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";	}	/**************************	 *	 * CLI functionality	 *	 *************************/	/**	 * CLI engine	 *	 * @param	array		Command line arguments	 * @return	string	 */	function cli_main($argv) {			// Force user to admin state and set workspace to "Live":		$GLOBALS['BE_USER']->user['admin'] = 1;		$GLOBALS['BE_USER']->setWorkspace(0);			// 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);			exit;		}			// Print help		$analysisType = (string)$this->cli_args['_DEFAULT'][1];		if (!$analysisType)	{			$this->cli_validateArgs();			$this->cli_help();			exit;		}			// Analysis type:		switch((string)$analysisType)    {			default:				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())	{							$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)':'')))	{									$cleanerMode->main_autofix($res);								} else {									$this->cli_echo("ABORTING AutoFix...\n",1);								}							}						}					} else {	// Help only...						$cleanerMode->cli_help();						exit;					}				} else {					$this->cli_echo("ERROR: Analysis Type '".$analysisType."' is unknown.\n",1);					exit;				}			break;		}	}	/**	 * Checks reference index	 *	 * @return	boolean		TRUE if reference index was OK (either OK, updated or ignored)	 */	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);			exit;		}		switch($refIndexMode)	{			case 'check':			case 'update':				$refIndexObj = t3lib_div::makeInstance('t3lib_refindex');				list($headerContent,$bodyContent,$errorCount) = $refIndexObj->updateIndex($refIndexMode=='check',$this->cli_echo());				if ($errorCount && $refIndexMode=='check')	{					$ok = FALSE;					$this->cli_echo("ERROR: Reference Index Check failed! (run with '--refindex update' to fix)\n",1);				} else {					$ok = TRUE;				}			break;			case 'ignore':				$this->cli_echo("Reference Index Check: Bypassing reference index check...\n");				$ok = TRUE;			break;		}		return $ok;	}	/**	 * @param	[type]		$matchString: ...	 * @return	string		If string, it's the reason for not executing. Returning FALSE means it should execute.	 */	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.'"';		}			// Check for interactive mode		if ($this->cli_isArg('-i'))	{			if (!$this->cli_keyboardInput_yes(' EXECUTE?'))	{				return 'BYPASS...';			}		}			// Check for		if ($this->cli_isArg('--dryrun'))	return 'BYPASS: --dryrun set';	}	/**	 * Formats a result array from a test so it fits output in the shell	 *	 * @param	string		name of the test (eg. function name)	 * @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)	{		$detailLevel = t3lib_div::intInRange($this->cli_isArg('-v') ? $this->cli_argValue('-v') : 1,0,3);		$silent = !$this->cli_echo();		$severity = array(			0 => 'MESSAGE',			1 => 'INFO',			2 => 'WARNING',			3 => 'ERROR',		);			// Header output:		if ($detailLevel <= 1)	{			$this->cli_echo(				"*********************************************\n".				$header."\n".				"*********************************************\n");			$this->cli_echo(wordwrap(trim($res['message'])).chr(10).chr(10));		}			// Traverse headers for output:		if (is_array($res['headers'])) {			foreach($res['headers'] as $key => $value)	{				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);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -