Projekt

Obecné

Profil

« Předchozí | Další » 

Revize c478920d

Přidáno uživatelem Ondřej Fibich před asi 9 roky(ů)

Undo my stupid mistake (I have pushed issue-957 to master instead of develop). Do I have copied files from GitHub master and push them back..

Zobrazit rozdíly:

application/controllers/installation.php
/*
* This file is part of open source system FreenetIS
* and it is released under GPLv3 licence.
*
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
*
*
* More info about project can be found:
* http://www.freenetis.org/
*
*
*/
/**
* Controller performs installation of FreenetIS
*
*
* @package Controller
*/
class Installation_Controller extends Controller
......
);
/**
* Page with installation dialog if not initialized database is configured
* or not properly setup. After form validation it creates member
* representing association, his primary user, first bank account and
* default double-entry accounts required for accounting.
* Function shows installation dialog. To show it must exist empty database freenetis and user with the
* same name. After form validation it creates member representing association, his primary user,
* first bank account and many double-entry accounts required for accounting.
*/
public function index()
{
// check if the database is empty
if (Settings::get('db_schema_version') && Settings::get('domain'))
{
url::redirect('members/show/' . $this->session->get('member_id'));
}
if (Settings::get('db_schema_version'))
url::redirect('members/show/'.$this->session->get('member_id'));
/**
/**
* finds default currency and country from lang
* @todo do it better, maybe from some special table
*/
......
break;
}
// form
// form
$form = new Forge('installation');
// login
$form->group('Login data');
$form->input('login')
->label('Username')
->rules('required|length[3,50]')
->value('admin')
->help(help::hint('login_name'))
->callback(array($this, 'valid_username'));
$pass_min_len = Settings::get('security_password_length');
$form->password('password')
->rules('required|length['.$pass_min_len.',50]')
->class('main_password')
->title(url_lang::lang('help.password'));
$form->password('confirm_password')
->rules('required|length['.$pass_min_len.',50]')
->matches($form->password);
// association
$form->group('Association information');
$form->input('name')
->label('Name of the association')
->rules('required|length[3,30]');
$form->date('foundation')
->label('Date of foundation')
->years(date('Y')-100, date('Y'))
->rules('required');
$form->input('street')
->rules('required|length[1,200]');
$form->input('street_number')
->rules('length[1,50]');
$form->input('town')
->rules('required|length[1,200]');
$form->input('quarter')
->rules('length[1,50]');
$form->input('zip_code')
->rules('required|length[5,10]');
$form->input('phone')
->rules('required|length[9,9]|valid_phone');
$form->input('email')
->rules('required|valid_email|length[3,50]');
// bank account
$form->group(
__('The first bank account information') . ' ' .
help::hint('bank_accounts_of_association')
);
$form->input('account_name')
->rules('required|length[3,50]');
$form->input('account_nr')
->label('Account number')
->rules('required|length[3,50]|valid_numeric');
$form->input('bank_nr')
->label('Bank code')
->rules('required|length[3,10]|valid_numeric');
$form->input('IBAN');
$form->input('SWIFT');
// fees
$form->group('Fees');
$form->input('deduct_day')
->rules('valid_numeric')
->help(help::hint('deduct_day'))
->rules('required')
->value(15);
$form->input('entrance_fee')
->rules('valid_numeric')
->help(help::hint('entrance_fee'));
$form->input('regular_member_fee')
->label('Monthly member fee')
->rules('valid_numeric');
$form->input('transfer_fee')
->rules('valid_numeric');
$form->input('penalty')
->rules('valid_numeric');
// system
$form->group('System');
$form->input('title')
->label('Page title')
->value('Freenetis')
->rules('required');
$form->dropdown('default_country')
->label('Country')
->rules('required')
->options(self::$COUNTRIES)
->selected($country_id)
->style('width:200px');
$form->input('currency')
->rules('required')
->value($currency);
// submit button
$form->submit('Install');
// valid post?
if ($form->validate())
{
$form_data = $form->as_array();
unset($form_data['confirm_password']);
$lck_file = server::base_dir() . '/upload/mutex';
try
{
// database init
$this->services->injectCoreDatabaseInit()->make($lck_file);
// setup association data
$setup_service = $this->services->injectCoreSetup();
$data = new freenetis\service\core\AssociationSetupData();
$data->set_values($form_data);
$data->domain = server::http_host();
$data->suffix = substr(server::script_name(), 0, -9);
$data->index_page = 0;
$setup_service->association($data);
// done
$view = new View('installation/done');
$view->render(TRUE);
exit();
}
catch (Exception $ex)
{
Log::add_exception($ex);
status::error('Installation has failed', $ex);
}
// try to open mutex file
if (($f = @fopen(server::base_dir().'/upload/mutex', 'w')) === FALSE)
{
// directory is not writeable
self::error(WRITABLE, server::base_dir().'/upload/');
}
// acquire an exclusive access to file
// wait while database is being updated
if (flock($f, LOCK_EX))
{
// first access - update db
// other access - skip
if (!Version::is_db_up_to_date())
{
// this executes all queries that upgrade database structure
try
{
Version::make_db_up_to_date();
}
catch (Exception $e)
{
throw new Exception(
__('Database upgrade failed') . ': ' .
$e->getMessage(), 0, $e
);
}
// data
$town_model = new Town_Model();
$street_model = new Street_Model();
try
{
$town_model->transaction_start();
// set deduct day
Settings::set('deduct_day', max(1, min(31, $form_data['deduct_day'])));
// first member is special, it represents association
$member = new Member_Model();
$member->registration = NULL;
$member->name = $form_data['name'];
// address
$town = $town_model->get_town(
$form_data['zip_code'],
$form_data['town'],
$form_data['quarter']
);
$street = $street_model->get_street($form_data['street'], $town->id);
$address_point_model = new Address_point_Model();
$address_point = $address_point_model->get_address_point(
$form_data['default_country'],
$town->id, $street->id,
$form_data['street_number']
);
// address point doesn't exist exist, create it
if (!$address_point->id)
{
$address_point->save_throwable();
}
$member->address_point_id = $address_point->id;
$enum_type = new Enum_type_Model();
$member->type = $enum_type->get_type_id('Honorary member');
$member->entrance_date = date('Y-m-d', $form_data['foundation']);
$member->save_throwable();
// every member has its one primary user of type "member"
$user = new User_Model();
$user->member_id = $member->id;
$user->name = $form_data['login'];
$user->surname = $form_data['login'];
$user->birthday = date('Y-m-d', $form_data['foundation']);
$user->login = $form_data['login'];
$user->password = sha1($form_data['password']);
$user->type = User_Model::MAIN_USER;
$user->application_password = security::generate_password();
$user->save_throwable();
// add user to access list as admin
$groups_aro_map = new Groups_aro_map_Model();
$groups_aro_map->aro_id = $user->id;
$groups_aro_map->group_id = Aro_group_Model::ADMINS;
$groups_aro_map->save_throwable();
// users telephone
$contact = new Contact_Model();
$contact->type = Contact_Model::TYPE_PHONE;
$contact->value = $form_data['phone'];
$contact->save_throwable();
$contact->add($user);
$contact->save_throwable();
$phone_country = new Country_Model($form_data['default_country']);
$contact->add($phone_country);
$contact->save_throwable();
$contact->clear();
// users email
if (! empty($form_data['email']))
{
$contact->type = Contact_Model::TYPE_EMAIL;
$contact->value = $form_data['email'];
$contact->save_throwable();
$contact->add($user);
$contact->save_throwable();
}
// association has at least one real bank account
$bank_account = new Bank_account_Model();
$bank_account->name = $form_data['account_name'];
$bank_account->member_id = $member->id;
$bank_account->account_nr = $form_data['account_nr'];
$bank_account->bank_nr = $form_data['bank_nr'];
$bank_account->IBAN = $form_data['IBAN'];
$bank_account->SWIFT = $form_data['SWIFT'];
$bank_account->save_throwable();
// these three double-entry accounts are related to one bank account through relation table
// double-entry bank account
$doubleentry_bank_account = new Account_Model();
$doubleentry_bank_account->member_id = $member->id;
$doubleentry_bank_account->name = $form_data['account_name'];
$doubleentry_bank_account->account_attribute_id = Account_attribute_Model::BANK;
$doubleentry_bank_account->comment = __('Bank accounts');
$doubleentry_bank_account->add($bank_account);
$doubleentry_bank_account->save_throwable();
// double-entry account of bank fees
$bank_fees_account = new Account_Model();
$bank_fees_account->member_id = $member->id;
$bank_fees_account->name = $form_data['account_name'].' - '.__('Bank fees');
$bank_fees_account->account_attribute_id = Account_attribute_Model::BANK_FEES;
$bank_fees_account->comment = __('Bank fees');
$bank_fees_account->add($bank_account);
$bank_fees_account->save_throwable();
// double-entry account of bank interests
$bank_interests_account = new Account_Model();
$bank_interests_account->member_id = $member->id;
$bank_interests_account->name = $form_data['account_name'].' - '.__('Bank interests');
$bank_interests_account->account_attribute_id = Account_attribute_Model::BANK_INTERESTS;
$bank_interests_account->comment = __('Bank interests');
$bank_interests_account->add($bank_account);
$bank_interests_account->save_throwable();
// other double entry accounts independent of bank account
// double-entry cash account
$cash_account = new Account_Model();
$cash_account->member_id = $member->id;
$cash_account->name = __('Cash');
$cash_account->account_attribute_id = Account_attribute_Model::CASH;
$cash_account->comment = __('Cash');
$cash_account->save_throwable();
// double-entry operating account
$operating_account = new Account_Model();
$operating_account->member_id = $member->id;
$operating_account->name = __('Operating account');
$operating_account->account_attribute_id = Account_attribute_Model::OPERATING;
$operating_account->comment = __('Operating account');
$operating_account->save_throwable();
// double-entry infrastructure account
$infrastructure_account = new Account_Model();
$infrastructure_account->member_id = $member->id;
$infrastructure_account->name = __('Infrastructure account');
$infrastructure_account->account_attribute_id = Account_attribute_Model::INFRASTRUCTURE;
$infrastructure_account->comment = __('Infrastructure account');
$infrastructure_account->save_throwable();
// double-entry account of purchasers
$purchasers_account = new Account_Model();
$purchasers_account->member_id = $member->id;
$purchasers_account->name = __('Purchasers account');
$purchasers_account->account_attribute_id = Account_attribute_Model::PURCHASERS;
$purchasers_account->comment = __('Purchasers account');
$purchasers_account->save_throwable();
// double-entry account of suppliers
$suppliers_account = new Account_Model();
$suppliers_account->member_id = $member->id;
$suppliers_account->name = __('Suppliers account');
$suppliers_account->account_attribute_id = Account_attribute_Model::SUPPLIERS;
$suppliers_account->comment = __('Suppliers account');
$suppliers_account->save_throwable();
// double-entry account of received member fees
$fees_account = new Account_Model();
$fees_account->member_id = $member->id;
$fees_account->name = __('Received member fees');
$fees_account->account_attribute_id = Account_attribute_Model::MEMBER_FEES;
$fees_account->comment = __('Received member fees');
$fees_account->save_throwable();
// interval of fee availability
$from = date('Y-m-d', $form_data['foundation']);
$to = '9999-12-31 23:59:59';
// entrance fee
$entrance_fee = new Fee_Model();
$entrance_fee->fee = $form_data['entrance_fee'];
$entrance_fee->from = $from;
$entrance_fee->to = $to;
$entrance_fee->type_id = $enum_type->get_type_id('entrance fee');
$entrance_fee->save_throwable();
// default entrance fee
$default_entrance_fee = new Members_fee_Model();
$default_entrance_fee->fee_id = $entrance_fee->id;
$default_entrance_fee->member_id = $member->id;
$default_entrance_fee->activation_date = $from;
$default_entrance_fee->deactivation_date = $to;
$default_entrance_fee->priority = 1;
$default_entrance_fee->save_throwable();
// regular member fee
$regular_member_fee = new Fee_Model();
$regular_member_fee->fee = $form_data['regular_member_fee'];
$regular_member_fee->from = $from;
$regular_member_fee->to = $to;
$regular_member_fee->type_id = $enum_type->get_type_id('regular member fee');
$regular_member_fee->save_throwable();
// default regular member fee
$default_regular_member_fee = new Members_fee_Model();
$default_regular_member_fee->fee_id = $regular_member_fee->id;
$default_regular_member_fee->member_id = $member->id;
$default_regular_member_fee->activation_date = $from;
$default_regular_member_fee->deactivation_date = $to;
$default_regular_member_fee->priority = 1;
$default_regular_member_fee->save_throwable();
// transfer fee
$transfer_fee = new Fee_Model();
$transfer_fee->fee = $form_data['transfer_fee'];
$transfer_fee->from = $from;
$transfer_fee->to = $to;
$transfer_fee->type_id = $enum_type->get_type_id('transfer fee');
$transfer_fee->save_throwable();
// default transfer fee
$default_transfer_fee = new Members_fee_Model();
$default_transfer_fee->fee_id = $transfer_fee->id;
$default_transfer_fee->member_id = $member->id;
$default_transfer_fee->activation_date = $from;
$default_transfer_fee->deactivation_date = $to;
$default_transfer_fee->priority = 1;
$default_transfer_fee->save_throwable();
// penalty
$penalty = new Fee_Model();
$penalty->fee = $form_data['penalty'];
$penalty->from = $from;
$penalty->to = $to;
$penalty->type_id = $enum_type->get_type_id('penalty');
$penalty->save_throwable();
// default transfer fee
$default_penalty = new Members_fee_Model();
$default_penalty->fee_id = $penalty->id;
$default_penalty->member_id = $member->id;
$default_penalty->activation_date = $from;
$default_penalty->deactivation_date = $to;
$default_penalty->priority = 1;
$default_penalty->save_throwable();
// permament whitelist
$members_whitelist = new Members_whitelist_Model();
$members_whitelist->member_id = $member->id;
$members_whitelist->permanent = 1;
$members_whitelist->since = date('Y-m-d');
$members_whitelist->until = '9999-12-31';
$members_whitelist->save_throwable();
// system settings
Settings::set('title', $form_data['title']);
Settings::set('currency', $form_data['currency']);
Settings::set('default_country', $form_data['default_country']);
// saves special (read-only) types of fee
$fee_model = new Fee_Model();
$special_types = array
(
1 => 'Membership interrupt',
2 => 'Fee-free regular member',
3 => 'Non-member',
4 => 'Honorary member'
);
foreach ($special_types as $id => $name)
{
$fee_model->clear();
$fee_model->readonly = 1;
$fee_model->fee = 0;
$fee_model->from = $from;
$fee_model->to = $to;
$fee_model->type_id = $enum_type->get_type_id('regular member fee');
$fee_model->name = $name;
$fee_model->special_type_id = $id;
$fee_model->save_throwable();
}
// commit changes
$town_model->transaction_commit();
}
catch (Exception $e)
{
$town_model->transaction_rollback();
Log::add_exception($e);
throw new Exception(__('Installation has failed') . ': ' . $e);
}
// array for store error
$errors = array();
// set base domain
Settings::set('domain', server::http_host());
// set subdirectory
$suffix = substr(server::script_name(),0,-9);
Settings::set('suffix', $suffix);
$view = new View('installation/done');
// remove index.php from urls
Settings::set('index_page', 0);
$view->errors = $errors;
$view->render(TRUE);
}
// unlock mutex file
flock($f, LOCK_UN);
}
// close mutex file
fclose($f);
}
else
{
$view = new View('installation/index');
$view->title = __('Installation');
$view->form = $form->html();
$view->render(TRUE);
}
$view = new View('installation/index');
$view->title = __('Installation');
$view->form = $form->html();
$view->render(TRUE);
}
/**
* Installation done page.
*/
public function done()
{
$view = new View('installation/done');
$view->render(TRUE);
}
/**
* Function checks validity of username.
*
*
* @param object $input
*/
public static function valid_username($input = NULL)
......
{
self::error(PAGE);
}
$username_regex = Settings::get('username_regex');
if (preg_match($username_regex, $input->value) == 0)
{
$input->add_error(
......
);
}
}
}

Také k dispozici: Unified diff