<commit_before><?php
namespace wcf\data\devtools\project;
use wcf\data\AbstractDatabaseObjectAction;
use wcf\data\package\installation\queue\PackageInstallationQueue;
use wcf\data\package\installation\queue\PackageInstallationQueueEditor;
use wcf\system\exception\IllegalLinkException;
use wcf\system\WCF;
use wcf\util\DirectoryUtil;
use wcf\util\FileUtil;

/**
 * Executes devtools project related actions.
 * 
 * @author	<NAME>, <NAME>
 * @copyright	2001-2018 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\Data\Devtools\Project
 * @since	3.1
 * 
 * @method	DevtoolsProjectEditor[]	getObjects()
 * @method	DevtoolsProjectEditor	getSingleObject()
 */
class DevtoolsProjectAction extends AbstractDatabaseObjectAction {
	/**
	 * @inheritDoc
	 */
	protected $className = DevtoolsProjectEditor::class;
	
	/**
	 * @inheritDoc
	 */
	protected $requireACP = ['delete', 'installPackage'];
	
	/**
	 * @inheritDoc
	 */
	protected $permissionsDelete = ['admin.configuration.package.canInstallPackage'];
	
	/**
	 * package installation queue for project to be installed from source
	 * @var		PackageInstallationQueue
	 * @since	3.2
	 */
	public $queue;
	
	/**
	 * @inheritDoc
	 */
	public function validateDelete() {
		if (!ENABLE_DEVELOPER_TOOLS) {
			throw new IllegalLinkException();
		}
		
		parent::validateDelete();
	}
	
	/**
	 * Validates the 'quickSetup' action.
	 * 
	 * @throws	IllegalLinkException
	 */
	public function validateQuickSetup() {
		if (!ENABLE_DEVELOPER_TOOLS) {
			throw new IllegalLinkException();
		}
		
		WCF::getSession()->checkPermissions(['admin.configuration.package.canInstallPackage']);
		
		$this->readString('path');
	}
	
	/**
	 * Quickly setups multiple projects by scanning a directory.
	 * 
	 * @return	array
	 */<commit_msg>Ensure that directory of newly created devtools project exists<commit_after><?php
namespace wcf\data\devtools\project;
use wcf\data\AbstractDatabaseObjectAction;
use wcf\data\package\installation\queue\PackageInstallationQueue;
use wcf\data\package\installation\queue\PackageInstallationQueueEditor;
use wcf\system\exception\IllegalLinkException;
use wcf\system\WCF;
use wcf\util\DirectoryUtil;
use wcf\util\FileUtil;

/**
 * Executes devtools project related actions.
 * 
 * @author	<NAME>, <NAME>
 * @copyright	2001-2018 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\Data\Devtools\Project
 * @since	3.1
 * 
 * @method	DevtoolsProjectEditor[]	getObjects()
 * @method	DevtoolsProjectEditor	getSingleObject()
 */
class DevtoolsProjectAction extends AbstractDatabaseObjectAction {
	/**
	 * @inheritDoc
	 */
	protected $className = DevtoolsProjectEditor::class;
	
	/**
	 * @inheritDoc
	 */
	protected $requireACP = ['delete', 'installPackage'];
	
	/**
	 * @inheritDoc
	 */
	protected $permissionsDelete = ['admin.configuration.package.canInstallPackage'];
	
	/**
	 * package installation queue for project to be installed from source
	 * @var		PackageInstallationQueue
	 * @since	3.2
	 */
	public $queue;
	
	/**
	 * @inheritDoc
	 * @return	DevtoolsProject
	 * @since	3.2
	 */
	public function create() {
		$this->parameters['data']['path'] = FileUtil::addTrailingSlash($this->parameters['data']['path']);
		
		/** @var DevtoolsProject $project */
		$project = parent::create();
		
		// ensure that the project directory exists
		FileUtil::makePath($project->path);
		
		return $project;
	}
	
	/**
	 * @inheritDoc
	 */
	public function validateDelete() {
		if (!ENABLE_DEVELOPER_TOOLS) {
			throw new IllegalLinkException();
		}
		
		parent::validateDelete();
	}
	
	/**
	 * Validates the 'quickSetup' action.
	 * 
	 * @throws	IllegalLinkException
	 */
	public function validateQuickSetup() {
		if (!ENABLE_DEVELOPER_TOOLS) {
			throw new IllegalLinkException();
		}
		
		WCF::getSession()->checkPermissions(['admin.configuration.package.canInstallPackage']);
		
		$this->readString('path');
	}
	
	/**
	 * Quickly setups multiple projects by scanning a directory.
	 * 
	 * @return	array
	 */
{'fraction_non_alphanumeric': 0.1280310378273521, 'fraction_numerical': 0.006304558680892337, 'mean_word_length': 4.32258064516129, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 16, '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': '6990825', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1211, 'n_words': 262}