[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [14562] booking: formatting code
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [14562] booking: formatting code |
Date: |
Thu, 10 Dec 2015 13:26:29 +0000 |
Revision: 14562
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=14562
Author: sigurdne
Date: 2015-12-10 13:26:28 +0000 (Thu, 10 Dec 2015)
Log Message:
-----------
booking: formatting code
Modified Paths:
--------------
branches/dev-syncromind/booking/tasks/cleanCompletedReservations.php
branches/dev-syncromind/booking/tasks/cleanReservations.php
branches/dev-syncromind/booking/tasks/entryPoint.php
branches/dev-syncromind/booking/tasks/getBookingAppVersion.php
branches/dev-syncromind/booking/tasks/randomReservations.php
branches/dev-syncromind/booking/tasks/sendReminder.php
branches/dev-syncromind/booking/tasks/setBookingAppVersion.php
branches/dev-syncromind/booking/tasks/testNumberGenerator.php
branches/dev-syncromind/booking/tasks/updateReservationState.php
Modified: branches/dev-syncromind/booking/tasks/cleanCompletedReservations.php
===================================================================
--- branches/dev-syncromind/booking/tasks/cleanCompletedReservations.php
2015-12-10 13:24:31 UTC (rev 14561)
+++ branches/dev-syncromind/booking/tasks/cleanCompletedReservations.php
2015-12-10 13:26:28 UTC (rev 14562)
@@ -1,13 +1,14 @@
<?php
- require_once dirname(__FILE__).'/entryPoint.php';
-
- function cleanCompletedReservations(PhpgwContext $c) {
+ require_once dirname(__FILE__) . '/entryPoint.php';
+
+ function cleanCompletedReservations(PhpgwContext $c)
+ {
$reservation_tables = array('bb_completed_reservation');
- foreach ($reservation_tables as $table) {
+ foreach($reservation_tables as $table)
+ {
$sql = "TRUNCATE table $table CASCADE";
- echo $sql."\n";
+ echo $sql . "\n";
$c->getDb()->query($sql, __LINE__, __FILE__);
}
}
-
- PhpgwEntry::phpgw_call('cleanCompletedReservations');
\ No newline at end of file
+ PhpgwEntry::phpgw_call('cleanCompletedReservations');
Modified: branches/dev-syncromind/booking/tasks/cleanReservations.php
===================================================================
--- branches/dev-syncromind/booking/tasks/cleanReservations.php 2015-12-10
13:24:31 UTC (rev 14561)
+++ branches/dev-syncromind/booking/tasks/cleanReservations.php 2015-12-10
13:26:28 UTC (rev 14562)
@@ -1,13 +1,14 @@
<?php
- require_once dirname(__FILE__).'/entryPoint.php';
-
- function cleanReservations(PhpgwContext $c) {
+ require_once dirname(__FILE__) . '/entryPoint.php';
+
+ function cleanReservations(PhpgwContext $c)
+ {
$reservation_tables = array('bb_booking', 'bb_allocation',
'bb_event');
- foreach ($reservation_tables as $table) {
+ foreach($reservation_tables as $table)
+ {
$sql = "TRUNCATE table $table CASCADE";
- echo $sql."\n";
+ echo $sql . "\n";
$c->getDb()->query($sql, __LINE__, __FILE__);
}
}
-
- PhpgwEntry::phpgw_call('cleanReservations');
\ No newline at end of file
+ PhpgwEntry::phpgw_call('cleanReservations');
Modified: branches/dev-syncromind/booking/tasks/entryPoint.php
===================================================================
--- branches/dev-syncromind/booking/tasks/entryPoint.php 2015-12-10
13:24:31 UTC (rev 14561)
+++ branches/dev-syncromind/booking/tasks/entryPoint.php 2015-12-10
13:26:28 UTC (rev 14562)
@@ -1,32 +1,38 @@
<?php
+
/**
- * An entryPoint for running tasks
- */
- interface PhpgwContext {
+ * An entryPoint for running tasks
+ */
+ interface PhpgwContext
+ {
+
function getDb();
}
-
+
class PhpgwEntry implements PhpgwContext
{
+
protected $db;
-
- function __construct($callable, $parameters = array()) {
+
+ function __construct($callable, $parameters = array())
+ {
$this->call($callable, $parameters);
}
-
- protected function in() {
- $path_to_phpgroupware = dirname(__FILE__) . '/../..';
// need to be adapted if this script is moved somewhere else
- $_GET['domain'] = 'default';
+ protected function in()
+ {
+ $path_to_phpgroupware = dirname(__FILE__) .
'/../..'; // need to be adapted if this script is moved somewhere else
+ $_GET['domain'] = 'default';
+
$GLOBALS['phpgw_info']['flags'] = array(
'currentapp' => 'login',
- 'noapi' => True // this stops
header.inc.php to include phpgwapi/inc/function.inc.php
+ 'noapi' => True // this stops
header.inc.php to include phpgwapi/inc/function.inc.php
);
/**
- * Include phpgroupware header
- */
- include($path_to_phpgroupware.'/header.inc.php');
+ * Include phpgroupware header
+ */
+ include($path_to_phpgroupware . '/header.inc.php');
unset($GLOBALS['phpgw_info']['flags']['noapi']);
@@ -35,7 +41,7 @@
{
$db_type = 'pgsql';
}
- if (!extension_loaded($db_type) && !dl($db_type.'.so'))
+ if(!extension_loaded($db_type) && !dl($db_type . '.so'))
{
echo "Extension '$db_type' is not loaded and
can't be loaded via dl('$db_type.so') !!!\n";
}
@@ -43,43 +49,50 @@
$GLOBALS['phpgw_info']['server']['sessions_type'] =
'db';
/**
- * Include API functions
- */
- include(PHPGW_API_INC.'/functions.inc.php');
-
- for ($i=0; $i < 10; $i++) {
+ * Include API functions
+ */
+ include(PHPGW_API_INC . '/functions.inc.php');
+
+ for($i = 0; $i < 10; $i++)
+ {
restore_error_handler(); //Remove at least 10
levels of custom error handling
}
-
- for ($i=0; $i < 10; $i++) {
+
+ for($i = 0; $i < 10; $i++)
+ {
restore_exception_handler(); //Remove at least
10 levels of custom exception handling
}
-
+
$this->initializeContext();
}
-
- protected function out() {
+
+ protected function out()
+ {
$GLOBALS['phpgw']->common->phpgw_exit();
}
-
- protected function initializeContext() {
+
+ protected function initializeContext()
+ {
phpgw::import_class('booking.bocommon_authorized');
booking_bocommon_authorized::disable_authorization();
- $this->db = &$GLOBALS['phpgw']->db;
+ $this->db = &$GLOBALS['phpgw']->db;
}
-
- public function getDb() {
+
+ public function getDb()
+ {
return $this->db;
}
-
- protected function call($callable, $parameters = array()) {
+
+ protected function call($callable, $parameters = array())
+ {
$this->in();
array_unshift($parameters, $this);
call_user_func_array($callable, $parameters);
$this->out();
}
-
- static public function phpgw_call($callable, $parameters =
array()) {
+
+ static public function phpgw_call($callable, $parameters =
array())
+ {
new self($callable, $parameters);
}
}
\ No newline at end of file
Modified: branches/dev-syncromind/booking/tasks/getBookingAppVersion.php
===================================================================
--- branches/dev-syncromind/booking/tasks/getBookingAppVersion.php
2015-12-10 13:24:31 UTC (rev 14561)
+++ branches/dev-syncromind/booking/tasks/getBookingAppVersion.php
2015-12-10 13:26:28 UTC (rev 14562)
@@ -1,12 +1,12 @@
<?php
- require_once dirname(__FILE__).'/entryPoint.php';
-
- function getBookingAppVersion(PhpgwContext $c) {
+ require_once dirname(__FILE__) . '/entryPoint.php';
+
+ function getBookingAppVersion(PhpgwContext $c)
+ {
$sql = "SELECT app_version FROM phpgw_applications WHERE
app_name = 'booking' LIMIT 1";
- echo $sql."\n";
+ echo $sql . "\n";
$c->getDb()->query($sql, __LINE__, __FILE__);
$c->getDb()->next_record();
- echo 'Current Version: '.$c->getDb()->f('app_version')."\n";
+ echo 'Current Version: ' . $c->getDb()->f('app_version') . "\n";
}
-
- PhpgwEntry::phpgw_call('getBookingAppVersion');
\ No newline at end of file
+ PhpgwEntry::phpgw_call('getBookingAppVersion');
Modified: branches/dev-syncromind/booking/tasks/randomReservations.php
===================================================================
--- branches/dev-syncromind/booking/tasks/randomReservations.php
2015-12-10 13:24:31 UTC (rev 14561)
+++ branches/dev-syncromind/booking/tasks/randomReservations.php
2015-12-10 13:26:28 UTC (rev 14562)
@@ -1,213 +1,236 @@
<?php
- require_once dirname(__FILE__).'/entryPoint.php';
-
- function randomReservations(PhpgwContext $c) {
+ require_once dirname(__FILE__) . '/entryPoint.php';
+
+ function randomReservations(PhpgwContext $c)
+ {
date_default_timezone_set('Europe/Stockholm');
-
+
$types = array('booking', 'event', 'allocation');
-
+
$options = array('season_id' => null, 'building_id');
-
- $options['season_id'] = isset($_ENV['SEASON_ID']) ?
$_ENV['SEASON_ID'] : null;
- $options['building_id'] = isset($_ENV['BUILDING_ID']) ?
$_ENV['BUILDING_ID'] : null;
-
- if (!$options['season_id']) {
+
+ $options['season_id'] = isset($_ENV['SEASON_ID']) ?
$_ENV['SEASON_ID'] : null;
+ $options['building_id'] = isset($_ENV['BUILDING_ID']) ?
$_ENV['BUILDING_ID'] : null;
+
+ if(!$options['season_id'])
+ {
throw new InvalidArgumentException('Missing SEASON_ID');
}
-
- $season_so = CreateObject('booking.soseason');
- $options['season'] =
$season_so->read_single($options['season_id']);
-
- if (!$options['season']) {
+
+ $season_so =
CreateObject('booking.soseason');
+ $options['season'] =
$season_so->read_single($options['season_id']);
+
+ if(!$options['season'])
+ {
throw new InvalidArgumentException('Invalid SEASON_ID');
}
-
+
$options['building_id'] = $options['season']['building_id'];
-
- if (!$options['building_id']) {
+
+ if(!$options['building_id'])
+ {
throw new InvalidArgumentException('Missing
BUILDING_ID');
}
-
+
$resource_so = CreateObject('booking.soresource');
-
+
$resources = $resource_so->read(array(
'filters' => array(
- 'building_id' => $options['building_id'],
- 'active' => 1,
+ 'building_id' => $options['building_id'],
+ 'active' => 1,
)
));
-
- if (!isset($resources['total_records']) ||
$resources['total_records'] < 1) {
+
+ if(!isset($resources['total_records']) ||
$resources['total_records'] < 1)
+ {
throw new InvalidArgumentException('Building with
BUILDING_ID has no available resources');
}
-
- $agegroup_bo = CreateObject('booking.boagegroup');
- $agegroups = $agegroup_bo->fetch_age_groups();
- $options['agegroups'] = $agegroups['results'];
-
- $activity_bo = CreateObject('booking.boactivity');
- $activities = $activity_bo->fetch_activities();
- $options['activities'] = $activities['results'];
-
- $groups_so = CreateObject('booking.sogroup');
- $groups = $groups_so->read(array(
+
+ $agegroup_bo =
CreateObject('booking.boagegroup');
+ $agegroups =
$agegroup_bo->fetch_age_groups();
+ $options['agegroups'] = $agegroups['results'];
+
+ $activity_bo =
CreateObject('booking.boactivity');
+ $activities =
$activity_bo->fetch_activities();
+ $options['activities'] = $activities['results'];
+
+ $groups_so =
CreateObject('booking.sogroup');
+ $groups = $groups_so->read(array(
'filters' => array('active' => '1')
));
- $options['groups'] = $groups['results'];
-
- $org_so = CreateObject('booking.soorganization');
- $organizations = $org_so->read(array(
+ $options['groups'] = $groups['results'];
+
+ $org_so =
CreateObject('booking.soorganization');
+ $organizations = $org_so->read(array(
'filters' => array('active' => '1')
));
- $options['organizations'] = $organizations['results'];
-
- $audience_bo = CreateObject('booking.boaudience');
- $audience = $audience_bo->fetch_target_audience();
+ $options['organizations'] = $organizations['results'];
+
+ $audience_bo = CreateObject('booking.boaudience');
+ $audience =
$audience_bo->fetch_target_audience();
$options['audience'] = $audience['results'];
-
- $resources = $resources['results'];
- $resources_length = count($resources);
-
+
+ $resources = $resources['results'];
+ $resources_length = count($resources);
+
//$date_funcs = array('set_future_date', 'set_current_date',
'set_past_date', 'set_past_date');
- $date_funcs = array('set_past_date', 'set_past_date');
- $date_funcs_length = count($date_funcs);
-
- foreach ($types as $type) {
- $initialize_func = 'initialize_'.$type;
-
- echo 'Now: '.date('Y-m-d H:i:s')."\n";
-
- for ($i=1; $i <= 10; $i++) {
- $data = array();
- $data['active'] = '1';
- $data['completed'] = '0';
- $reservation = CreateObject('booking.bo'.$type);
- $date_func =
$date_funcs[rand(0,$date_funcs_length-1)];
- $data = call_user_func_array($date_func,
array($data));
- $data['resources'] =
select_resources($resources, rand(1, $resources_length));
- $data['cost'] = rand(30,200)+(rand(1,99)/100);
- $activity =
select_activity($options['activities'], rand(0,
count($options['activities'])-1));
- $data['activity_id'] = $activity['id'];
- $data['activity_name'] = $activity['name'];
- $data = call_user_func_array($initialize_func,
array($data, $options));
+ $date_funcs = array('set_past_date',
'set_past_date');
+ $date_funcs_length = count($date_funcs);
+
+ foreach($types as $type)
+ {
+ $initialize_func = 'initialize_' . $type;
+
+ echo 'Now: ' . date('Y-m-d H:i:s') . "\n";
+
+ for($i = 1; $i <= 10; $i++)
+ {
+ $data =
array();
+ $data['active'] = '1';
+ $data['completed'] = '0';
+ $reservation =
CreateObject('booking.bo' . $type);
+ $date_func =
$date_funcs[rand(0, $date_funcs_length - 1)];
+ $data =
call_user_func_array($date_func, array($data));
+ $data['resources'] =
select_resources($resources, rand(1, $resources_length));
+ $data['cost'] = rand(30,
200) + (rand(1, 99) / 100);
+ $activity =
select_activity($options['activities'], rand(0, count($options['activities']) -
1));
+ $data['activity_id'] = $activity['id'];
+ $data['activity_name'] = $activity['name'];
+ $data =
call_user_func_array($initialize_func, array($data, $options));
$reservation->add($data);
}
}
}
-
- function generate_random_organization_number() {
+
+ function generate_random_organization_number()
+ {
$rand_nums = array();
- for ($i=0; $i < 9; $i++) {
- $rand_nums[] = rand(1,9);
+ for($i = 0; $i < 9; $i++)
+ {
+ $rand_nums[] = rand(1, 9);
}
return join($rand_nums, '');
}
-
- function generate_random_ssn() {
- return str_pad(rand(1,28), 2, 0, STR_PAD_LEFT). /* Dag */
- str_pad(rand(1,12), 2, 0, STR_PAD_LEFT). /* Måned */
- str_pad(rand(0,99), 2, 0, STR_PAD_LEFT). /* År
*/
- rand(100,999).
/* Individsiffre + Kön */
- str_pad(rand(0,99), 2, 0, STR_PAD_LEFT); /*
Kontroll */
+
+ function generate_random_ssn()
+ {
+ return str_pad(rand(1, 28), 2, 0, STR_PAD_LEFT) . /* Dag */
+ str_pad(rand(1, 12), 2, 0, STR_PAD_LEFT) . /* Måned */
+ str_pad(rand(0, 99), 2, 0, STR_PAD_LEFT) . /* År */
+ rand(100, 999) . /* Individsiffre + Kön */
+ str_pad(rand(0, 99), 2, 0, STR_PAD_LEFT); /* Kontroll */
}
-
- function set_random_customer_identifier(&$entity) {
+
+ function set_random_customer_identifier(&$entity)
+ {
static $customer_identifier_types = array('ssn',
'organization_number');
static $customer_id;
-
- $current_type = $customer_identifier_types[rand(0,1)];
- $entity['customer_identifier_type'] = $current_type;
- $entity['customer_'.$current_type] = $current_id =
call_user_func('generate_random_'.$current_type);
-
- if (count($errors =
CreateObject('booking.customer_identifier')->validate($entity)) > 0) {
+
+ $current_type =
$customer_identifier_types[rand(0, 1)];
+ $entity['customer_identifier_type'] = $current_type;
+ $entity['customer_' . $current_type] = $current_id
= call_user_func('generate_random_' .
$current_type);
+
+ if(count($errors =
CreateObject('booking.customer_identifier')->validate($entity)) > 0)
+ {
throw new LogicException(
- sprintf('Unable to create valid random customer
%s. Generated %s', $current_type, $current_id)
+ sprintf('Unable to create valid random customer %s.
Generated %s', $current_type, $current_id)
);
}
}
-
- function initialize_booking($data, $options) {
- $data['season_id'] = $options['season_id'];
- $agegroups = array();
-
- foreach ($options['agegroups'] as $agegroup) {
- $agegroups[] = array('agegroup_id' => $agegroup['id'],
'female' => (string)rand(1,3), 'male' => (string)rand(1,3));
+
+ function initialize_booking($data, $options)
+ {
+ $data['season_id'] = $options['season_id'];
+ $agegroups = array();
+
+ foreach($options['agegroups'] as $agegroup)
+ {
+ $agegroups[] = array('agegroup_id' => $agegroup['id'],
'female' => (string)rand(1, 3),
+ 'male' => (string)rand(1, 3));
}
-
+
$audiences = array();
-
- foreach ($options['audience'] as $audience) {
+
+ foreach($options['audience'] as $audience)
+ {
$audiences[] = $audience['id'];
}
-
+
$data['audience'] = $audiences;
-
+
$data['agegroups'] = $agegroups;
-
- $group = $options['groups'][rand(0,
count($options['groups'])-1)];
-
+
+ $group = $options['groups'][rand(0, count($options['groups']) -
1)];
+
$data['group_id'] = $group['id'];
return $data;
}
-
- function initialize_event($data, $options) {
- $data['description'] = $data['activity_name'].':
'.$data['from_'].' - '.$data['to_'];
- $data['contact_name'] = 'John Doe';
- $data['contact_email'] = 'address@hidden';
- $data['contact_phone'] = '123456789';
+
+ function initialize_event($data, $options)
+ {
+ $data['description'] = $data['activity_name'] . ': ' .
$data['from_'] . ' - ' . $data['to_'];
+ $data['contact_name'] = 'John Doe';
+ $data['contact_email'] = 'address@hidden';
+ $data['contact_phone'] = '123456789';
set_random_customer_identifier($data);
return initialize_booking($data, $options);
- }
-
- function initialize_allocation($data, $options) {
+ }
+
+ function initialize_allocation($data, $options)
+ {
$data['season_id'] = $options['season_id'];
-
- $org = $options['organizations'][rand(0,
count($options['organizations'])-1)];
-
+
+ $org = $options['organizations'][rand(0,
count($options['organizations']) - 1)];
+
$data['organization_id'] = $org['id'];
return $data;
}
-
- function select_activity(&$activities, $position) {
+
+ function select_activity(&$activities, $position)
+ {
$activity = $activities[$position];
return $activity;
}
-
- function select_resources(&$available_resources, $number) {
+
+ function select_resources(&$available_resources, $number)
+ {
$resources = array();
- for ($i=0; $i < $number; $i++) {
+ for($i = 0; $i < $number; $i++)
+ {
$resources[] = $available_resources[$i]['id'];
}
return $resources;
}
-
- function set_future_date($data) {
- $start_date = strtotime(sprintf('+%s days +%s hours',
rand(1,40), rand(12, 24)));
- $end_date = strtotime(sprintf('+%s days +%s hours', rand(1,4),
rand(1, 3)), $start_date);
- $data['from_'] = date('Y-m-d H:i', $start_date).':00';
- $data['to_'] = date('Y-m-d H:i', $end_date).':00';
- echo 'Future date: '.$data['from_'].' - '.$data['to_']."\n";
+
+ function set_future_date($data)
+ {
+ $start_date = strtotime(sprintf('+%s days +%s
hours', rand(1, 40), rand(12, 24)));
+ $end_date = strtotime(sprintf('+%s days +%s
hours', rand(1, 4), rand(1, 3)), $start_date);
+ $data['from_'] = date('Y-m-d H:i', $start_date) . ':00';
+ $data['to_'] = date('Y-m-d H:i', $end_date) . ':00';
+ echo 'Future date: ' . $data['from_'] . ' - ' . $data['to_'] .
"\n";
return $data;
}
- function set_past_date($data) {
- $end_date = strtotime(sprintf('-%s days -%s hours', rand(2,40),
rand(1,12)));
- $start_date = strtotime(sprintf('-%s days -%s hours',
rand(1,4), rand(1, 3)), $end_date);
-
- $data['from_'] = date('Y-m-d H:i', $start_date).':00';
- $data['to_'] = date('Y-m-d H:i', $end_date).':00';
- echo 'Past date: '.$data['from_'].' - '.$data['to_']."\n";
+ function set_past_date($data)
+ {
+ $end_date = strtotime(sprintf('-%s days -%s hours',
rand(2, 40), rand(1, 12)));
+ $start_date = strtotime(sprintf('-%s days -%s hours',
rand(1, 4), rand(1, 3)), $end_date);
+
+ $data['from_'] = date('Y-m-d H:i', $start_date) . ':00';
+ $data['to_'] = date('Y-m-d H:i', $end_date) . ':00';
+ echo 'Past date: ' . $data['from_'] . ' - ' . $data['to_'] .
"\n";
return $data;
}
-
- function set_current_date($data) {
- $start_date = strtotime(sprintf('-%s days -%s hours',
rand(0,2), rand(1, 6)));
- $end_date = strtotime(sprintf('+%s days +%s hours', rand(0,2),
rand(1, 6)));
-
- $data['from_'] = date('Y-m-d H:i', $start_date).':00';
- $data['to_'] = date('Y-m-d H:i', $end_date).':00';
- echo 'Current date: '.$data['from_'].' - '.$data['to_']."\n";
+
+ function set_current_date($data)
+ {
+ $start_date = strtotime(sprintf('-%s days -%s hours',
rand(0, 2), rand(1, 6)));
+ $end_date = strtotime(sprintf('+%s days +%s hours',
rand(0, 2), rand(1, 6)));
+
+ $data['from_'] = date('Y-m-d H:i', $start_date) . ':00';
+ $data['to_'] = date('Y-m-d H:i', $end_date) . ':00';
+ echo 'Current date: ' . $data['from_'] . ' - ' . $data['to_'] .
"\n";
return $data;
}
-
- PhpgwEntry::phpgw_call('randomReservations');
\ No newline at end of file
+ PhpgwEntry::phpgw_call('randomReservations');
Modified: branches/dev-syncromind/booking/tasks/sendReminder.php
===================================================================
--- branches/dev-syncromind/booking/tasks/sendReminder.php 2015-12-10
13:24:31 UTC (rev 14561)
+++ branches/dev-syncromind/booking/tasks/sendReminder.php 2015-12-10
13:26:28 UTC (rev 14562)
@@ -1,8 +1,8 @@
<?php
- require_once dirname(__FILE__).'/entryPoint.php';
-
- function sendReminder(PhpgwContext $c) {
+ require_once dirname(__FILE__) . '/entryPoint.php';
+
+ function sendReminder(PhpgwContext $c)
+ {
CreateObject('booking.async_task_send_reminder')->run();
}
-
PhpgwEntry::phpgw_call('sendReminder');
Modified: branches/dev-syncromind/booking/tasks/setBookingAppVersion.php
===================================================================
--- branches/dev-syncromind/booking/tasks/setBookingAppVersion.php
2015-12-10 13:24:31 UTC (rev 14561)
+++ branches/dev-syncromind/booking/tasks/setBookingAppVersion.php
2015-12-10 13:26:28 UTC (rev 14562)
@@ -1,21 +1,21 @@
<?php
- require_once dirname(__FILE__).'/entryPoint.php';
-
- function setBookingAppVersion(PhpgwContext $c) {
+ require_once dirname(__FILE__) . '/entryPoint.php';
+
+ function setBookingAppVersion(PhpgwContext $c)
+ {
$options = array('version' => null);
-
+
$options['version'] = (isset($_ENV['VERSION']) &&
strlen($_ENV['VERSION'] > 0)) ? $_ENV['VERSION'] : null;
-
- if (!$options['version']) {
+
+ if(!$options['version'])
+ {
throw new InvalidArgumentException('Missing VERSION');
}
-
+
$sql = sprintf(
- "UPDATE phpgw_applications SET app_version = '%s' WHERE
app_name = 'booking'",
- $options['version']
+ "UPDATE phpgw_applications SET app_version = '%s' WHERE
app_name = 'booking'", $options['version']
);
- echo $sql."\n";
+ echo $sql . "\n";
$c->getDb()->query($sql, __LINE__, __FILE__);
}
-
- PhpgwEntry::phpgw_call('setBookingAppVersion');
\ No newline at end of file
+ PhpgwEntry::phpgw_call('setBookingAppVersion');
Modified: branches/dev-syncromind/booking/tasks/testNumberGenerator.php
===================================================================
--- branches/dev-syncromind/booking/tasks/testNumberGenerator.php
2015-12-10 13:24:31 UTC (rev 14561)
+++ branches/dev-syncromind/booking/tasks/testNumberGenerator.php
2015-12-10 13:26:28 UTC (rev 14562)
@@ -1,137 +1,156 @@
<?php
- require_once dirname(__FILE__).'/entryPoint.php';
-
- function get_external_generator() {
- $numberGenerator =
CreateObject('booking.sobilling_sequential_number_generator');
- assert('$numberGenerator instanceof
booking_sobilling_sequential_number_generator')
- AND pass_test('$numberGenerator instanceof
booking_sobilling_sequential_number_generator');
+ require_once dirname(__FILE__) . '/entryPoint.php';
+
+ function get_external_generator()
+ {
+ $numberGenerator =
CreateObject('booking.sobilling_sequential_number_generator');
+ assert('$numberGenerator instanceof
booking_sobilling_sequential_number_generator')
+ AND pass_test('$numberGenerator instanceof
booking_sobilling_sequential_number_generator');
$numberGeneratorInstance =
$numberGenerator->get_generator_instance('external');
- assert('$numberGeneratorInstance instanceof
booking_sobilling_sequential_number_generator_instance')
- AND pass_test('$numberGeneratorInstance
instanceof booking_sobilling_sequential_number_generator_instance');
+ assert('$numberGeneratorInstance instanceof
booking_sobilling_sequential_number_generator_instance')
+ AND pass_test('$numberGeneratorInstance instanceof
booking_sobilling_sequential_number_generator_instance');
return $numberGeneratorInstance;
}
-
- function testNumberGenerator(PhpgwContext $c) {
+
+ function testNumberGenerator(PhpgwContext $c)
+ {
$numberGeneratorInstance = get_external_generator();
-
+
###############################################################
$logic_exception_if_no_active_transaction = false;
- try {
+ try
+ {
$numberGeneratorInstance->increment();
- } catch (LogicException $e) {
+ }
+ catch(LogicException $e)
+ {
$logic_exception_if_no_active_transaction = true;
}
assert('$logic_exception_if_no_active_transaction') and
pass_test('logic_exception_if_no_active_transaction');
-
+
#############################################################
print_info("Pre Transaction");
$c->getDb()->transaction_begin(); //Begin transaction
$no_logic_exception_if_active_transaction = false;
-
- try {
+
+ try
+ {
$numberGeneratorInstance->increment();
- $currentValue = $numberGeneratorInstance->get_current();
+ $currentValue
= $numberGeneratorInstance->get_current();
$numberGeneratorInstance->increment();
$numberGeneratorInstance->increment();
- $no_logic_exception_if_active_transaction = true;
- } catch (LogicException $e) { }
+ $no_logic_exception_if_active_transaction = true;
+ }
+ catch(LogicException $e)
+ {
+
+ }
$c->getDb()->transaction_abort();
-
+
assert($no_logic_exception_if_active_transaction) AND
pass_test("no_logic_exception_if_active_transaction");
-
+
print_info("Post Transaction");
#############################################################
-
+
$previousNumberGeneratorInstance = $numberGeneratorInstance;
- $numberGeneratorInstance = get_external_generator();
-
+ $numberGeneratorInstance =
get_external_generator();
+
$new_generator_is_created_post_transaction =
$previousNumberGeneratorInstance != $numberGeneratorInstance;
-
+
assert('$new_generator_is_created_post_transaction') AND
pass_test("new_generator_is_created_post_transaction");
-
+
#############################################################
print_info("Start Transaction");
$c->getDb()->transaction_begin(); //Begin transaction
#############################################################
-
+
$cannotGetCurrentWithoutLock = false;
-
- try {
+
+ try
+ {
$numberGeneratorInstance->get_current();
- } catch (Exception $e) {
+ }
+ catch(Exception $e)
+ {
print_info($e->getMessage());
$cannotGetCurrentWithoutLock = true;
}
-
+
assert('$cannotGetCurrentWithoutLock') AND pass_test("Cannot
get current without lock");
-
+
##############################################################
-
- $canGetCurrentWithLock = false;
+
+ $canGetCurrentWithLock = false;
$numberGeneratorInstance->increment(); //Locked
print_info("Locked (->increment)");
- $previousValue = $numberGeneratorInstance->get_current();
+ $previousValue =
$numberGeneratorInstance->get_current();
$numberGeneratorInstance->increment();
- $canGetCurrentWithLock = true;
+ $canGetCurrentWithLock = true;
assert($canGetCurrentWithLock) AND pass_test("Able to
get_current with lock");
-
+
############################################################
assert('$numberGeneratorInstance->get_current() ===
$previousValue+1') AND pass_test("Incremented value by one");
############################################################
-
+
$c->getDb()->transaction_abort();
print_info("Abort transaction");
-
+
############################################################
$unableToUseGeneratorPostTransaction = false;
-
- try {
+
+ try
+ {
$numberGeneratorInstance->get_current();
- } catch (LogicException $e) {
+ }
+ catch(LogicException $e)
+ {
$unableToUseGeneratorPostTransaction = true;
}
-
+
assert($unableToUseGeneratorPostTransaction) AND
pass_test("Unable to use generator post transaction");
-
+
print_info("Sleep test");
$c->getDb()->transaction_begin(); //Begin transaction
$numberGeneratorInstance = get_external_generator();
sleep(4);
- for ($i=0; $i < 10; $i++) {
+ for($i = 0; $i < 10; $i++)
+ {
print_info($numberGeneratorInstance->increment()->get_current());
}
$c->getDb()->transaction_abort();
sleep(4);
-
+
print_info("Sleep test 2");
$c->getDb()->transaction_begin(); //Begin transaction
$numberGeneratorInstance = get_external_generator();
sleep(4);
- for ($i=0; $i < 10; $i++) {
+ for($i = 0; $i < 10; $i++)
+ {
print_info($numberGeneratorInstance->increment()->get_current());
}
$c->getDb()->transaction_commit();
sleep(4);
}
-
- function pass_test($message) {
- echo "PASSED: ".$message."\n";
+
+ function pass_test($message)
+ {
+ echo "PASSED: " . $message . "\n";
}
-
- function print_info($message) {
- echo "INFO: ".$message."\n";
+
+ function print_info($message)
+ {
+ echo "INFO: " . $message . "\n";
}
-
+
// Create a handler function
function my_assert_handler($file, $line, $code)
{
- echo "Assertion Failed:\n".
- "File '$file'\n".
- "Line '$line'\n".
- "Code '$code'\n";
+ echo "Assertion Failed:\n" .
+ "File '$file'\n" .
+ "Line '$line'\n" .
+ "Code '$code'\n";
}
-
// Set up the callback
assert_options(ASSERT_CALLBACK, 'my_assert_handler');
- PhpgwEntry::phpgw_call('testNumberGenerator');
\ No newline at end of file
+ PhpgwEntry::phpgw_call('testNumberGenerator');
Modified: branches/dev-syncromind/booking/tasks/updateReservationState.php
===================================================================
--- branches/dev-syncromind/booking/tasks/updateReservationState.php
2015-12-10 13:24:31 UTC (rev 14561)
+++ branches/dev-syncromind/booking/tasks/updateReservationState.php
2015-12-10 13:26:28 UTC (rev 14562)
@@ -1,8 +1,8 @@
<?php
- require_once dirname(__FILE__).'/entryPoint.php';
-
- function updateReservationState(PhpgwContext $c) {
+ require_once dirname(__FILE__) . '/entryPoint.php';
+
+ function updateReservationState(PhpgwContext $c)
+ {
CreateObject('booking.async_task_update_reservation_state')->run();
}
-
- PhpgwEntry::phpgw_call('updateReservationState');
\ No newline at end of file
+ PhpgwEntry::phpgw_call('updateReservationState');
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [14562] booking: formatting code,
Sigurd Nes <=