<commit_before><?php

$dir = dirname(__FILE__);

if (file_exists($dir . '/config.lock')) {
	throw new Exception('locked');
}

if (!is_writable($dir)) {
	//throw new Exception('modules/setup folder needs write permission');
}

if (!file_exists($dir . '/config.php')) {
	throw new Exception('You must first create modules/setup/config.php');
}

require_once $dir . '/../../vendor/autoload.php';
require_once $dir . '/../setup/config.php';

use RedBeanPHP\R;
use Enpowi\Users\Group;
use Enpowi\Users\User;
use Enpowi\Users\Perm;

R::nuke();

Enpowi\App::log('setup', 'newSite');

//create groups
$everyoneGroup = Group::create('Everyone', false, false, true);
$anonymousGroup = Group::create('Anonymous', false, true);
$registeredGroup = Group::create('Registered', true);
$administratorGroup = Group::create('Administrator', false, false, false, true);

//create first user & put him in admin group
$administratorUser = User::create('admin', 'admin', '', true);
$administratorGroup->addUser($administratorUser);

//give Anonymous abilities
Perm::create('user', 'login', $anonymousGroup);
Perm::create('user', 'register', $anonymousGroup);

//give registered abilities
Perm::create('user', 'view', $registeredGroup);
Perm::create('user', 'logout', $registeredGroup);
Perm::create('user', 'confirm', $registeredGroup);
Perm::create('page', 'edit', $registeredGroup);

//give Administrator group access to everything
Perm::create('*', '*', $administratorGroup);

//give everyone the ability to see modules with no security
Perm::create('app', '*', $everyoneGroup);
Perm::create('default', '*', $everyoneGroup);
Perm::create('setup', '*', $everyoneGroup);
Perm::create('page', 'index', $everyoneGroup);

file_put_contents($dir . '/config.lock', '');

echo 'setup complete';<commit_msg>ensure settup of site acts correctly<commit_after><?php

$dir = dirname(__FILE__);

define('path', dirname(dirname($dir)));

if (file_exists($dir . '/config.lock')) {
	throw new Exception('locked');
}

if (!is_writable($dir)) {
	//throw new Exception('modules/setup folder needs write permission');
}

if (!file_exists($dir . '/config.php')) {
	throw new Exception('You must first create modules/setup/config.php');
}

require_once $dir . '/../../vendor/autoload.php';
require_once $dir . '/../setup/config.php';

use RedBeanPHP\R;
use Enpowi\Users\Group;
use Enpowi\Users\User;
use Enpowi\Users\Perm;
use Enpowi\App;
use Enpowi\Modules\Module;

Module::run();
R::nuke();

App::log('setup', 'newSite');

//create groups
$everyoneGroup = Group::create('Everyone', false, false, true);
$anonymousGroup = Group::create('Anonymous', false, true);
$registeredGroup = Group::create('Registered', true);
$administratorGroup = Group::create('Administrator', false, false, false, true);

//create first user & put him in admin group
$administratorUser = User::create('admin', 'admin', '', true);
$administratorGroup->addUser($administratorUser);

//give Anonymous abilities
Perm::create('user', 'login', $anonymousGroup);
Perm::create('user', 'register', $anonymousGroup);

//give registered abilities
Perm::create('user', 'view', $registeredGroup);
Perm::create('user', 'logout', $registeredGroup);
Perm::create('user', 'confirm', $registeredGroup);
Perm::create('page', 'edit', $registeredGroup);

//give Administrator group access to everything
Perm::create('*', '*', $administratorGroup);

//give everyone the ability to see modules with no security
Perm::create('app', '*', $everyoneGroup);
Perm::create('default', '*', $everyoneGroup);
Perm::create('setup', '*', $everyoneGroup);
Perm::create('page', 'index', $everyoneGroup);

if (is_writable($dir)) {
    echo 'cannot write lock file. ';
} else {
    file_put_contents($dir . '/config.lock', '');
}

echo 'setup complete';
{'fraction_non_alphanumeric': 0.19546666666666668, 'fraction_numerical': 0.0, 'mean_word_length': 6.5625, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7287954', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1148, 'n_words': 288}