<commit_before><?php
namespace wcf\system\package\plugin;
use wcf\data\package\Package;
use wcf\data\package\PackageList;
use wcf\system\exception\SystemException;
use wcf\system\form\container\GroupFormElementContainer;
use wcf\system\form\element\LabelFormElement;
use wcf\system\form\FormDocument;
use wcf\system\package\PackageInstallationFormManager;
use wcf\system\package\PackageInstallationSQLParser;
use wcf\system\WCF;
use wcf\util\StringUtil;

/**
 * Executes the delivered sql file.
 * 
 * @author	<NAME>
 * @copyright	2001-2013 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	com.woltlab.wcf
 * @subpackage	system.package.plugin
 * @category	Community Framework
 */
class SQLPackageInstallationPlugin extends AbstractPackageInstallationPlugin {
	/**
	 * @see	wcf\system\package\plugin\AbstractPackageInstallationPlugin::$tableName
	 */
	public $tableName = 'package_installation_sql_log';
	
	/**
	 * @see	wcf\system\package\plugin\IPackageInstallationPlugin::install()
	 */
	public function install() {
		parent::install();
		
		// extract sql file from archive
		if ($queries = $this->getSQL($this->instruction['value'])) {
			$package = $this->installation->getPackage();
			
			// replace app1_ with app{WCF_N}_ in the table names for
			// all applications
			$packageList = new PackageList();
			$packageList->getConditionBuilder()->add('package.isApplication = ?', array(1));
			$packageList->readObjects();
			foreach ($packageList as $package) {
				$abbreviation = Package::getAbbreviation($package->package);
				
				$queries = StringUtil::replace($abbreviation.'1_', $abbreviation.WCF_N.'_', $queries);
			}
			
			// check queries
			$parser = new PackageInstallationSQLParser($queries, $this->installation->getPackage(), $this->installation->getAction());
			$conflicts = $parser->test();
			if (!empty($conflicts) && (isset($conflicts['CREATE TABLE']) || isset($conflicts['DROP TABLE']))) {
				WCF::getTPL()->assign(array(
					'conflicts' => $conflicts
				));
				
				throw new SystemException(WCF::getTPL()->fetch('packageInstallationDatabaseConflict'));
			}
			
			// execute queries
			$parser->execute();
			<commit_msg>Fixes issue with SystemException during package installation<commit_after><?php
namespace wcf\system\package\plugin;
use wcf\data\package\Package;
use wcf\data\package\PackageList;
use wcf\system\exception\SystemException;
use wcf\system\form\container\GroupFormElementContainer;
use wcf\system\form\element\LabelFormElement;
use wcf\system\form\FormDocument;
use wcf\system\package\PackageInstallationFormManager;
use wcf\system\package\PackageInstallationSQLParser;
use wcf\system\WCF;
use wcf\util\StringUtil;

/**
 * Executes the delivered sql file.
 * 
 * @author	<NAME>
 * @copyright	2001-2013 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	com.woltlab.wcf
 * @subpackage	system.package.plugin
 * @category	Community Framework
 */
class SQLPackageInstallationPlugin extends AbstractPackageInstallationPlugin {
	/**
	 * @see	wcf\system\package\plugin\AbstractPackageInstallationPlugin::$tableName
	 */
	public $tableName = 'package_installation_sql_log';
	
	/**
	 * @see	wcf\system\package\plugin\IPackageInstallationPlugin::install()
	 */
	public function install() {
		parent::install();
		
		// extract sql file from archive
		if ($queries = $this->getSQL($this->instruction['value'])) {
			$package = $this->installation->getPackage();
			
			// replace app1_ with app{WCF_N}_ in the table names for
			// all applications
			$packageList = new PackageList();
			$packageList->getConditionBuilder()->add('package.isApplication = ?', array(1));
			$packageList->readObjects();
			foreach ($packageList as $package) {
				$abbreviation = Package::getAbbreviation($package->package);
				
				$queries = StringUtil::replace($abbreviation.'1_', $abbreviation.WCF_N.'_', $queries);
			}
			
			// check queries
			$parser = new PackageInstallationSQLParser($queries, $this->installation->getPackage(), $this->installation->getAction());
			$conflicts = $parser->test();
			if (!empty($conflicts) && (isset($conflicts['CREATE TABLE']) || isset($conflicts['DROP TABLE']))) {
				$unknownCreateTable = isset($conflicts['CREATE TABLE']) ? $conflicts['CREATE TABLE'] : array();
				$unknownDropTable = isset($conflicts['DROP TABLE']) ? $conflicts['DROP TABLE'] : array();
				
				$errorMessage = "Can't";
				if (!empty($unknownDropTable)) {
					$errorMessage .= " drop unknown table";
					if (count($unknownDropTable) > 1) {
						$errorMessage .= "s";
					}
					$errorMessage .= " '".implode("', '", $unknownDropTable)."'";
				}
				if (!empty($unknownCreateTable)) {
					if (!empty($unknownDropTable)) {
						$errorMessage .= " and can't";
					}
					
					$errorMessage .= " overwrite unknown table";
					if (count($unknownCreateTable) > 1) {
						$errorMessage .= "s";
					}
					$errorMessage .= " '".implode("', '", $unknownCreateTable)."'";
				}
				
				throw new SystemException($errorMessage);
			}
			
			// execute queries
			$parser->execute();
			
{'fraction_non_alphanumeric': 0.15102356122054847, 'fraction_numerical': 0.004634994206257242, 'mean_word_length': 4.4230366492146596, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4828058', 'n_tokens_mistral': 1835, 'n_tokens_neox': 1544, 'n_words': 298}