From 3e92578753bdddd48a675b0921fe7ed29fee4fb0 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 27 Apr 2016 07:10:04 +0000 Subject: [PATCH] fix some ocurences with: instanceof , which is no longer true, when object is from new Api, but old extends new Api class --- calendar/inc/class.calendar_rrule.inc.php | 66 +++++++++++------------ setup/inc/class.setup_cmd.inc.php | 16 +++--- 2 files changed, 42 insertions(+), 40 deletions(-) diff --git a/calendar/inc/class.calendar_rrule.inc.php b/calendar/inc/class.calendar_rrule.inc.php index 4344898968..f25f2588bb 100644 --- a/calendar/inc/class.calendar_rrule.inc.php +++ b/calendar/inc/class.calendar_rrule.inc.php @@ -6,11 +6,13 @@ * @package calendar * @author Ralf Becker * @author Joerg Lehrke - * @copyright (c) 2009-15 by RalfBecker-At-outdoor-training.de + * @copyright (c) 2009-16 by RalfBecker-At-outdoor-training.de * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @version $Id$ */ +use EGroupware\Api; + /** * Recurrence rule iterator * @@ -182,14 +184,14 @@ class calendar_rrule implements Iterator /** * Starttime of series * - * @var egw_time + * @var Api\DateTime */ public $time; /** * Current "position" / time * - * @var egw_time + * @var Api\DateTime */ public $current; @@ -234,11 +236,11 @@ class calendar_rrule implements Iterator $this->lastdayofweek = self::SUNDAY; } - $this->time = $time instanceof egw_time ? $time : new egw_time($time); + $this->time = $time instanceof Api\DateTime ? $time : new Api\DateTime($time); if (!in_array($type,array(self::NONE, self::DAILY, self::WEEKLY, self::MONTHLY_MDAY, self::MONTHLY_WDAY, self::YEARLY))) { - throw new egw_exception_wrong_parameter(__METHOD__."($time,$type,$interval,$enddate,$weekdays,...) type $type is NOT valid!"); + throw new Api\Exception\WrongParameter(__METHOD__."($time,$type,$interval,$enddate,$weekdays,...) type $type is NOT valid!"); } $this->type = $type; @@ -350,7 +352,7 @@ class calendar_rrule implements Iterator private static function daysInMonth(DateTime $time) { list($year,$month) = explode('-',$time->format('Y-m')); - $last_day = new egw_time(); + $last_day = new Api\DateTime(); $last_day->setDate($year,$month+1,0); return (int)$last_day->format('d'); @@ -437,7 +439,7 @@ class calendar_rrule implements Iterator break; default: - throw new egw_exception_assertion_failed(__METHOD__."() invalid type #$this->type !"); + throw new Api\Exception\AssertionFailed(__METHOD__."() invalid type #$this->type !"); } } @@ -600,13 +602,13 @@ class calendar_rrule implements Iterator } if ($this->enddate) { - if ($this->enddate->getTimezone()->getName() != egw_time::$user_timezone->getName()) + if ($this->enddate->getTimezone()->getName() != Api\DateTime::$user_timezone->getName()) { - $this->enddate->setTimezone(egw_time::$user_timezone); + $this->enddate->setTimezone(Api\DateTime::$user_timezone); } - $str_extra[] = lang('ends').': '.lang($this->enddate->format('l')).', '.$this->enddate->format(egw_time::$user_dateformat); + $str_extra[] = lang('ends').': '.lang($this->enddate->format('l')).', '.$this->enddate->format(Api\DateTime::$user_dateformat); } - if ($this->time->getTimezone()->getName() != egw_time::$user_timezone->getName()) + if ($this->time->getTimezone()->getName() != Api\DateTime::$user_timezone->getName()) { $str_extra[] = $this->time->getTimezone()->getName(); } @@ -725,8 +727,8 @@ class calendar_rrule implements Iterator { if (!is_array($event) || !isset($event['tzid'])) return false; if (!$to_tz) $to_tz = $event['tzid']; - $timestamp_tz = $usertime ? egw_time::$user_timezone : egw_time::$server_timezone; - $time = is_a($event['start'],'DateTime') ? $event['start'] : new egw_time($event['start'],$timestamp_tz); + $timestamp_tz = $usertime ? Api\DateTime::$user_timezone : Api\DateTime::$server_timezone; + $time = is_a($event['start'],'DateTime') ? $event['start'] : new Api\DateTime($event['start'],$timestamp_tz); if (!isset(self::$tz_cache[$to_tz])) { @@ -739,13 +741,13 @@ class calendar_rrule implements Iterator if ($event['recur_enddate']) { - $enddate = is_a($event['recur_enddate'],'DateTime') ? $event['recur_enddate'] : new egw_time($event['recur_enddate'],$timestamp_tz); + $enddate = is_a($event['recur_enddate'],'DateTime') ? $event['recur_enddate'] : new Api\DateTime($event['recur_enddate'],$timestamp_tz); } if (is_array($event['recur_exception'])) { foreach($event['recur_exception'] as $exception) { - $exceptions[] = is_a($exception,'DateTime') ? $exception : new egw_time($exception,$timestamp_tz); + $exceptions[] = is_a($exception,'DateTime') ? $exception : new Api\DateTime($exception,$timestamp_tz); } } return new calendar_rrule($time,$event['recur_type'],$event['recur_interval'],$enddate,$event['recur_data'],$exceptions); @@ -796,7 +798,7 @@ class calendar_rrule implements Iterator } $time = is_a($starttime,'DateTime') ? - $starttime : new egw_time($starttime, egw_time::$server_timezone); + $starttime : new Api\DateTime($starttime, Api\DateTime::$server_timezone); $time->setTimezone(self::$tz_cache[$event['tzid']]); $remote = clone $time; $remote->setTimezone(self::$tz_cache[$to_tz]); @@ -832,13 +834,11 @@ if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE_ error_reporting(E_ALL & ~E_NOTICE); function lang($str) { return $str; } $GLOBALS['egw_info']['user']['preferences']['common']['tz'] = $_REQUEST['user-tz'] ? $_REQUEST['user-tz'] : 'Europe/Berlin'; - require_once('../../phpgwapi/inc/class.egw_time.inc.php'); - require_once('../../phpgwapi/inc/class.html.inc.php'); - require_once('../../phpgwapi/inc/class.egw_exception.inc.php'); + require_once('../../api/src/autoload.php'); if (!isset($_REQUEST['time'])) { - $now = new egw_time('now',new DateTimeZone($_REQUEST['tz'] = 'UTC')); + $now = new Api\DateTime('now',new DateTimeZone($_REQUEST['tz'] = 'UTC')); $_REQUEST['time'] = $now->format(); $_REQUEST['type'] = calendar_rrule::WEEKLY; $_REQUEST['interval'] = 2; @@ -847,31 +847,31 @@ if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE_ $_REQUEST['user-tz'] = 'Europe/Berlin'; } echo "\n\n\tTest calendar_rrule class\n\n\n
\n"; - echo "

Date+Time: ".html::input('time',$_REQUEST['time']). - html::select('tz',$_REQUEST['tz'],egw_time::getTimezones())."

\n"; - echo "

Type: ".html::select('type',$_REQUEST['type'],calendar_rrule::$types)."\n". - "Interval: ".html::input('interval',$_REQUEST['interval'])."

\n"; + echo "

Date+Time: ".Api\Html::input('time',$_REQUEST['time']). + Api\Html::select('tz',$_REQUEST['tz'],Api\DateTime::getTimezones())."

\n"; + echo "

Type: ".Api\Html::select('type',$_REQUEST['type'],calendar_rrule::$types)."\n". + "Interval: ".Api\Html::input('interval',$_REQUEST['interval'])."

\n"; echo "
\n"; - echo "Weekdays:
".html::checkbox_multiselect('weekdays',$_REQUEST['weekdays'],calendar_rrule::$days,false,'','7',false,'height: 150px;')."\n"; + echo "Weekdays:
".Api\Html::checkbox_multiselect('weekdays',$_REQUEST['weekdays'],calendar_rrule::$days,false,'','7',false,'height: 150px;')."\n"; echo "
\n"; - echo "

Exceptions:
".html::textarea('exceptions',$_REQUEST['exceptions'],'style="height: 150px;"')."\n"; + echo "

Exceptions:
".Api\Html::textarea('exceptions',$_REQUEST['exceptions'],'style="height: 150px;"')."\n"; echo "

\n"; - echo "

Enddate: ".html::input('enddate',$_REQUEST['enddate'])."

\n"; - echo "

Display recurances in ".html::select('user-tz',$_REQUEST['user-tz'],egw_time::getTimezones())."

\n"; - echo "

".html::submit_button('calc','Calculate')."

\n"; + echo "

Enddate: ".Api\Html::input('enddate',$_REQUEST['enddate'])."

\n"; + echo "

Display recurances in ".Api\Html::select('user-tz',$_REQUEST['user-tz'],Api\DateTime::getTimezones())."

\n"; + echo "

".Api\Html::submit_button('calc','Calculate')."

\n"; echo "
\n"; $tz = new DateTimeZone($_REQUEST['tz']); - $time = new egw_time($_REQUEST['time'],$tz); - if ($_REQUEST['enddate']) $enddate = new egw_time($_REQUEST['enddate'],$tz); + $time = new Api\DateTime($_REQUEST['time'],$tz); + if ($_REQUEST['enddate']) $enddate = new Api\DateTime($_REQUEST['enddate'],$tz); $weekdays = 0; foreach((array)$_REQUEST['weekdays'] as $mask) { $weekdays |= $mask; } - if ($_REQUEST['exceptions']) foreach(preg_split("/[,\r\n]+ ?/",$_REQUEST['exceptions']) as $exception) { $exceptions[] = new egw_time($exception); } + if ($_REQUEST['exceptions']) foreach(preg_split("/[,\r\n]+ ?/",$_REQUEST['exceptions']) as $exception) { $exceptions[] = new Api\DateTime($exception); } $rrule = new calendar_rrule($time,$_REQUEST['type'],$_REQUEST['interval'],$enddate,$weekdays,$exceptions); echo "

".$time->format('l').', '.$time.' ('.$tz->getName().') '.$rrule."

\n"; foreach($rrule as $rtime) { - $rtime->setTimezone(egw_time::$user_timezone); + $rtime->setTimezone(Api\DateTime::$user_timezone); echo ++$n.': '.$rtime->format('l').', '.$rtime."
\n"; } echo "\n\n"; diff --git a/setup/inc/class.setup_cmd.inc.php b/setup/inc/class.setup_cmd.inc.php index 2dc7cfe09a..8ad3f0ee2c 100644 --- a/setup/inc/class.setup_cmd.inc.php +++ b/setup/inc/class.setup_cmd.inc.php @@ -5,11 +5,13 @@ * @link http://www.egroupware.org * @author Ralf Becker * @package setup - * @copyright (c) 2007-14 by Ralf Becker + * @copyright (c) 2007-16 by Ralf Becker * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @version $Id$ */ +use EGroupware\Api\Egw; + /** * setup command: abstract baseclass for all setup commands, extending admin_cmd */ @@ -85,7 +87,7 @@ abstract class setup_cmd extends admin_cmd /** * Saving the object to the database, reimplemented to not do it in setup context * - * @param boolean $set_modifier=true set the current user as modifier or 0 (= run by the system) + * @param boolean $set_modifier =true set the current user as modifier or 0 (= run by the system) * @return boolean true on success, false otherwise */ function save($set_modifier=true) @@ -120,7 +122,7 @@ abstract class setup_cmd extends admin_cmd self::$egw_setup->ConfigDomain = $domain; if (isset($GLOBALS['egw_info']['server']['header_admin_user']) && !isset($GLOBALS['egw_domain']) && - is_object($GLOBALS['egw']) && $GLOBALS['egw'] instanceof egw) + is_object($GLOBALS['egw']) && $GLOBALS['egw'] instanceof Egw) { // we run inside eGW, not setup --> read egw_domain array from the header via the showheader cmd $cmd = new setup_cmd_showheader(null); // null = only header, no db stuff, no hashes @@ -172,7 +174,7 @@ abstract class setup_cmd extends admin_cmd * * @param string $user * @param string $pw - * @param string $domain=null if given we also check agains config user/pw + * @param string $domain =null if given we also check agains config user/pw * @throws egw_exception_no_permission(lang('Access denied: wrong username or password for manage-header !!!'),21); * @throws egw_exception_no_permission(lang("Access denied: wrong username or password to configure the domain '%1(%2)' !!!",$domain,$GLOBALS['egw_domain'][$domain]['db_type']),40); */ @@ -219,9 +221,9 @@ abstract class setup_cmd extends admin_cmd * * Sets self::$apps_to_update and self::$apps_to_install for the last/only domain only! * - * @param string $domain='' domain to check, default '' = all - * @param int/array $stop=0 stop checks before given exit-code(s), default 0 = all checks - * @param boolean $verbose=false echo messages as they happen, instead returning them + * @param string $domain ='' domain to check, default '' = all + * @param int/array $stop =0 stop checks before given exit-code(s), default 0 = all checks + * @param boolean $verbose =false echo messages as they happen, instead returning them * @return array with translated messages */ static function check_installed($domain='',$stop=0,$verbose=false)