From 38ef760c16cad9e4966855596483e27968625407 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 30 Apr 2015 09:40:21 +0000 Subject: [PATCH] * Calendar: when trying to load new holidays overwrite existing ones to not accumulate old ones (slowing down calendar) --- calendar/inc/class.boholiday.inc.php | 2 +- calendar/inc/class.soholiday.inc.php | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/calendar/inc/class.boholiday.inc.php b/calendar/inc/class.boholiday.inc.php index a9adf0a982..085b6a0b61 100755 --- a/calendar/inc/class.boholiday.inc.php +++ b/calendar/inc/class.boholiday.inc.php @@ -259,7 +259,7 @@ $total_year == $this->so->holiday_total($locale, '', 1901))) { //error_log(__METHOD__."('$locale', $year) attemption autoload ..."); - egw_cache::setInstance(__CLASS__, $locale.'-'.$year, true, 86400); // do NOT try again for 1 day + egw_cache::setInstance(__CLASS__, $locale.'-'.$year, true, 864000); // do NOT try again for 10 days @set_time_limit(0); /* get the file that contains the calendar events for your locale */ diff --git a/calendar/inc/class.soholiday.inc.php b/calendar/inc/class.soholiday.inc.php index 442d9d8a62..b13e56c48f 100755 --- a/calendar/inc/class.soholiday.inc.php +++ b/calendar/inc/class.soholiday.inc.php @@ -45,7 +45,7 @@ class soholiday { if (!is_numeric($name)) { - $holiday['hol_'.$name] = $holiday[$name]; + $holiday['hol_'.$name] = $val; } unset($holiday[$name]); } @@ -68,6 +68,12 @@ class soholiday { echo "Inserting LOCALE='".$holiday['locale']."' NAME='".$holiday['name']."' extra=(".$holiday['mday'].'/'.$holiday['month_num'].'/'.$holiday['occurence'].'/'.$holiday['dow'].'/'.$holiday['observance_rule'].")
\n"; } + // delete evtl. existing rules with same name, year (occurence) and local + $this->db->delete($this->table, array( + 'hol_name' => $holiday['hol_name'], + 'hol_occurence' => $holiday['hol_occurence'], + 'hol_locale' => $holiday['hol_locale'], + ), __LINE__, __FILES__, 'calendar'); $this->db->insert($this->table,$holiday,False,__LINE__,__FILE__,'calendar'); } } @@ -136,7 +142,7 @@ class soholiday { $this->db->delete($this->table,array('hol_locale' => $locale),__LINE__,__FILE__,'calendar'); } - + /* Private functions */ function _build_where($locales,$query='',$order='',$year=0,$add_order_by=True) { @@ -171,18 +177,20 @@ class soholiday { $querymethod = 'hol_locale LIKE '.$this->db->quote('%'.$query.'%'); } - + if(!preg_match('/^[a-zA-Z0-9_,]+$/',$order)) { - $order = 'hol_local'; + $order = 'hol_locale'; } - foreach($this->db->select($this->table,'DISTINCT hol_locale',$querymethod,__LINE__,__FILE__,false,$order,'calendar') as $row) + if (strtoupper($sort) != 'DESC') $sort = 'ASC'; + if (strpos($order, ',') === false) $order .= ' '.$sort; + foreach($this->db->select($this->table,'DISTINCT hol_locale',$querymethod,__LINE__,__FILE__,false,'ORDER BY '.$order,'calendar') as $row) { $locale[] = $row['hol_locale']; } return $locale; } - + function holiday_total($locale,$query='',$year=0) { $where = $this->_build_where($locale,$query,'',$year,False); @@ -191,7 +199,7 @@ class soholiday { echo 'HOLIDAY_TOTAL : '.$where.'
'."\n"; } - + $retval = $this->db->select($this->table,'count(*)',$where,__LINE__,__FILE__,false,'','calendar')->fetchColumn(); if($this->debug)