<commit_before><?php
namespace Rocketeer\Commands;

class DeployDeployCommand extends BaseDeployCommand
{

	/**
	 * The console command name.
	 *
	 * @var string
	 */
	protected $name = 'deploy:deploy';

	/**
	 * The console command description.
	 *
	 * @var string
	 */
	protected $description = 'Deploy the website.';

	/**
	 * Execute the tasks
	 *
	 * @return array
	 */
	public function fire()
	{
		$this->getReleasesManager()->updateCurrentRelease(time());

		$this->remote->run($this->getTasks());
		$this->call('deploy:cleanup');
	}

	/**
	 * The tasks to execute
	 *
	 * @return array
	 */
	public function tasks()
	{
		$currentReleasePath = $this->getReleasesManager()->getCurrentReleasePath();

		return array(
			$this->cloneRelease(),
			$this->removeFolder('current'),
			$this->updateSymlink(),

			$this->gotoFolder($currentReleasePath),
			$this->runComposer(),
			$this->runBower(),
			$this->runBasset(),
			"chmod -R +x " .$currentReleasePath.'/app',
			"chmod -R +x " .$currentReleasePath.'/public',
			"chown -R www-data:www-data " .$currentReleasePath.'/app',
			"chown -R www-data:www-data " .$currentReleasePath.'/public',
		);
	}

}<commit_msg>Setup on deploy if necessary<commit_after><?php
namespace Rocketeer\Commands;

class DeployDeployCommand extends BaseDeployCommand
{

	/**
	 * The console command name.
	 *
	 * @var string
	 */
	protected $name = 'deploy:deploy';

	/**
	 * The console command description.
	 *
	 * @var string
	 */
	protected $description = 'Deploy the website.';

	/**
	 * Execute the tasks
	 *
	 * @return array
	 */
	public function fire()
	{
		// Setup if necessary
		if (!$this->isSetup()) {
			$this->call('deploy:setup');
		}

		// Update current release
		$this->getReleasesManager()->updateCurrentRelease(time());

		$this->remote->run($this->getTasks());
		$this->call('deploy:cleanup');
	}

	/**
	 * The tasks to execute
	 *
	 * @return array
	 */
	public function tasks()
	{
		$currentReleasePath = $this->getReleasesManager()->getCurrentReleasePath();

		return array(
			// Clone release and update symlink
			$this->cloneRelease(),
			$this->removeFolder('current'),
			$this->updateSymlink(),

			// Run composer
			$this->gotoFolder($currentReleasePath),
			$this->runComposer(),

			// Set permissions
			"chmod -R +x " .$currentReleasePath.'/app',
			"chmod -R +x " .$currentReleasePath.'/public',
			"chown -R www-data:www-data " .$currentReleasePath.'/app',
			"chown -R www-data:www-data " .$currentReleasePath.'/public',
		);
	}

	////////////////////////////////////////////////////////////////////
	/////////////////////////////// HELPERS ////////////////////////////
	////////////////////////////////////////////////////////////////////

	/**
	 * Check if the remote server is set up
	 *
	 * @return boolean
	 */
	protected function isSetup()
	{
		$isSetup = null;
		$this->remote->run(array(
			'cd '.$this->getRocketeer()->getHomeFolder(),
		), function($remoteFolder) use (&$isSetup) {
			$isSetup = !str_contains($remoteFolder, 'no such file or directory');
		});

		return $isSetup;
	}

}
{'fraction_non_alphanumeric': 0.22493489583333334, 'fraction_numerical': 0.0, 'mean_word_length': 2.653983353151011, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, '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': '245531', 'n_tokens_mistral': 1064, 'n_tokens_neox': 933, 'n_words': 199}