hasArray('prepare_dirs')) { return; } $prepareDirs = $this->get('prepare_dirs'); foreach ($prepareDirs as $dir) { if (test('[ ! -e "{{remote_path}}/' . $dir . '" ]')) { run($this->getSudo() . ' mkdir -p {{remote_path}}/' . $dir); } } } /** * Change usergroup for the hole project */ public function changeGroup(): void { if ($this->get('http_group')) { $sudo = get('writable_use_sudo') ? 'sudo' : ''; $runOpts = []; if ($sudo) { $runOpts['tty'] = $this->get('writable_tty', false); } $path = parse('{{remote_path}}/releases/{{release_name}}/'); run($sudo . ' chgrp -H -R ' . $this->get('http_group') . ' ' . $path, $runOpts); run($sudo . ' chmod -R 2755 ' . $path, $runOpts); } } /** * Set files and/or folders writable */ public function writable(): void { if ($this->hasArray('writable_dirs') || $this->hasArray('writable_files')) { $sudo = get('writable_use_sudo') ? 'sudo' : ''; $runOpts = []; if ($sudo) { $runOpts['tty'] = get('writable_tty', false); } $recursive = $this->get('writable_recursive') ? '-R' : ''; $httpGroup = $this->get('http_group', false); $path = parse('{{remote_path}}/releases/{{release_name}}/'); if ($this->hasArray('writable_dirs')) { foreach ($this->get('writable_dirs') as $dir) { if (test('[ ! -d "' . $path . $dir . '" ]')) { run('mkdir -p ' . $path . $dir); } run($sudo . ' chmod -R 2775 ' . $path . $dir); if ($httpGroup) { run( $sudo . ' chgrp -H ' . $recursive . ' ' . $httpGroup . ' ' . $path . $dir, $runOpts ); } } } if ($this->hasArray('writable_files')) { foreach ($this->get('writable_files') as $file) { if (test('[ -e "' . $path . $file . '" ]')) { run($sudo . ' chmod g+w ' . $path . $file); if ($httpGroup) { run($sudo . ' chgrp ' . $httpGroup . ' ' . $path . $file, $runOpts); } } } } } } /** * Database migration */ public function dbCompare(): void { $path = parse('{{app_container_path}}') ?: parse('{{remote_path}}'); $php = $this->getSudo() . parse('{{bin/php}} '); if (!str_contains($php, 'TYPO3_CONTEXT')) { $php = $this->getApplicationContext() . $php; } $result = run( $php . $this->getTYPO3Bin($path, parse('{{remote_path}}')) . ' database:updateschema "*.add,*.change"' ); writeln($result); } /** * Fix folder structure */ public function fixFolderStructure(): void { $path = parse('{{app_container_path}}') ?: parse('{{remote_path}}'); $php = $this->getSudo() . parse('{{bin/php}} '); if (!str_contains($php, 'TYPO3_CONTEXT')) { $php = $this->getApplicationContext() . $php; } $result = run( $php . $this->getTYPO3Bin($path, parse('{{remote_path}}')) . ' install:fixfolderstructure' ); writeln($result); } /** * Clear cache via typo3 cache:flush */ public function clearCache(): void { $path = parse('{{app_container_path}}') ?: parse('{{remote_path}}'); $php = $this->getSudo() . parse('{{bin/php}} '); if (!str_contains($php, 'TYPO3_CONTEXT')) { $php = $this->getApplicationContext() . $php; } $result = run($php . $this->getTYPO3Bin($path, parse('{{remote_path}}')) . ' cache:flush'); writeln($result); } /** * Clear opcache via curl on {CI_HOST}/cache.php */ public function clearOpcache(): void { $htaccess = $this->has('htaccess') ? '--user ' . $this->get('htaccess') : ''; run('curl ' . $htaccess . ' -sk https://' . currentHost()->getAlias() . '/cache.php'); } protected function getSudo(): string { return $this->get('clear_use_sudo') ? 'sudo ' : ''; } protected function getApplicationContext(): string { return $this->has('application_context') ? 'TYPO3_CONTEXT="' . $this->get('application_context') . '" ' : ''; } protected function getTYPO3Bin(string $path, string $testPath): string { if (test('[ -f ' . $testPath . '/releases/{{release_name}}/vendor/bin/typo3cms ]')) { $bin = $path . '/releases/{{release_name}}/vendor/bin/typo3cms'; } else { $bin = $path . '/releases/{{release_name}}/vendor/bin/typo3'; } return $bin; } }