Newscoop\Installer\Services\FinishService::setupHtaccess PHP Method

setupHtaccess() public method

Makes backup of current .htaccess file and copy the latest one
public setupHtaccess ( ) : array
return array
    public function setupHtaccess()
    {
        $htaccess = '/.htaccess';
        $errors = array();
        try {
            if ($this->filesystem->exists($this->newscoopDir . $htaccess)) {
                $this->filesystem->copy(realpath($this->newscoopDir . $htaccess), realpath($this->newscoopDir) . '/htaccess.bak');
            }
        } catch (IOException $e) {
            $errors[] = $e->getMessage();
            return $errors;
        }
        try {
            $this->filesystem->copy(realpath($this->newscoopDir . '/htaccess.dist'), realpath($this->newscoopDir) . $htaccess, true);
        } catch (IOException $e) {
            $errors[] = $e->getMessage();
        }
        return $errors;
    }

Usage Example

Example #1
0
<?php

$newscoopDir = realpath(dirname(__FILE__) . '/../../../../../../') . '/';
require_once $newscoopDir . 'vendor/autoload.php';
use Newscoop\Installer\Services\FinishService;
$upgradeErrors = array();
$finishService = new FinishService();
$result = $finishService->setupHtaccess();
if (!empty($result)) {
    $msg = implode(" ", $result) . " Most likely it's caused by wrong permissions. Make a backup of .htaccess manually.\nThen copy " . $newscoopDir . "htaccess.dist to " . $newscoopDir . ".htaccess";
    $logger->addError($msg);
    $upgradeErrors[] = $msg;
}