Skip to content

Commit

Permalink
Improved PHP8.2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
rskrzypczak committed Aug 21, 2023
1 parent 9c2d40a commit d3e2a71
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 255 deletions.
2 changes: 1 addition & 1 deletion config/version.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

return [
'appVersion' => '6.4.285',
'appVersion' => '6.4.286',
'patchVersion' => '2023.08.21',
'lib_roundcube' => '0.3.4',
];
83 changes: 46 additions & 37 deletions include/CRMEntity.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php

/* * *******************************************************************************
* The contents of this file are subject to the SugarCRM Public License Version 1.1.2
* ("License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is: SugarCRM Open Source
* The Initial Developer of the Original Code is SugarCRM, Inc.
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
* All Rights Reserved.
* Contributor(s): YetiForce S.A.
* ****************************************************************************** */
/* * *******************************************************************************
* The contents of this file are subject to the SugarCRM Public License Version 1.1.2
* ("License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is: SugarCRM Open Source
* The Initial Developer of the Original Code is SugarCRM, Inc.
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
* All Rights Reserved.
* Contributor(s): YetiForce S.A.
* ****************************************************************************** */
/* * *******************************************************************************
* $Header: /advent/projects/wesat/vtiger_crm/vtigercrm/data/CRMEntity.php,v 1.16 2005/04/29 04:21:31 mickie Exp $
* Description: Defines the base class for all data entities used throughout the
Expand Down Expand Up @@ -79,6 +79,16 @@ public function __construct()
$this->column_fields = vtlib\Deprecated::getColumnFields(static::class);
}

/**
* Get module name.
*
* @return string
*/
public function getName(): string
{
return static::class;
}

/**
* Get CRMEntity instance.
*
Expand All @@ -105,36 +115,13 @@ public static function getInstance(string $module)
}
}
$focus = new $module();
$focus->moduleName = $module;
if (method_exists($focus, 'init')) {
$focus->init();
}
\App\Cache::staticSave('CRMEntity', $module, clone $focus);
return $focus;
}

/**
* Loading the system configuration.
*
* @return void
*/
protected function init(): void
{
$this->tab_name_index += ['u_yf_wapro_records_map' => 'crmid'];
}

/**
* Function returns the column alias for a field.
*
* @param array $fieldInfo - field information
*
* @return string field value
*/
protected function createColumnAliasForField(array $fieldInfo)
{
return strtolower($fieldInfo['tablename'] . $fieldInfo['fieldname']);
}

/**
* Retrieve record information of the module.
*
Expand Down Expand Up @@ -180,7 +167,7 @@ public function retrieveEntityInfo(int $record, string $module)
foreach ($cachedModuleFields as $fieldInfo) {
$fieldvalue = '';
$fieldkey = $this->createColumnAliasForField($fieldInfo);
//Note : value is retrieved with a tablename+fieldname as we are using alias while building query
// Note : value is retrieved with a tablename+fieldname as we are using alias while building query
if (isset($resultRow[$fieldkey])) {
$fieldvalue = $resultRow[$fieldkey];
}
Expand Down Expand Up @@ -287,4 +274,26 @@ public function moduleHandler($moduleName, $eventType)
} elseif ('module.postupdate' === $eventType) {
}
}

/**
* Loading the system configuration.
*
* @return void
*/
protected function init(): void
{
$this->tab_name_index += ['u_yf_wapro_records_map' => 'crmid'];
}

/**
* Function returns the column alias for a field.
*
* @param array $fieldInfo - field information
*
* @return string field value
*/
protected function createColumnAliasForField(array $fieldInfo)
{
return strtolower($fieldInfo['tablename'] . $fieldInfo['fieldname']);
}
}
179 changes: 90 additions & 89 deletions include/fields/DateTimeField.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,91 @@ public function __construct($value)
$this->datetime = $value;
}

/**
* @param string $date
* @param string $format
*
* @return string
*/
public static function __convertToDBFormat($date, $format)
{
if (empty($date)) {
\App\Log::trace('End ' . __METHOD__);

return $date;
}
if ('' == $format) {
$format = 'yyyy-mm-dd';
}
return \App\Fields\Date::sanitizeDbFormat($date, $format);
}

/**
* @param string $date
* @param string $format
*
* @return string
*/
public static function __convertToUserFormat($date, $format)
{
\App\Log::trace('Start ' . __METHOD__ . ' ' . serialize($date) . ' | ' . $format);
if (!\is_array($date)) {
$date = explode(' ', $date);
}
$separator = '-';
if (false !== strpos($date[0], '-')) {
$separator = '-';
} elseif (false !== strpos($date[0], '.')) {
$separator = '.';
} elseif (false !== strpos($date[0], '/')) {
$separator = '/';
}
[$y, $m, $d] = array_pad(explode($separator, $date[0]), 3, null);

switch ($format) {
case 'dd-mm-yyyy':
$date[0] = $d . '-' . $m . '-' . $y;
break;
case 'mm-dd-yyyy':
$date[0] = $m . '-' . $d . '-' . $y;
break;
case 'yyyy-mm-dd':
$date[0] = $y . '-' . $m . '-' . $d;
break;
case 'dd.mm.yyyy':
$date[0] = $d . '.' . $m . '.' . $y;
break;
case 'mm.dd.yyyy':
$date[0] = $m . '.' . $d . '.' . $y;
break;
case 'yyyy.mm.dd':
$date[0] = $y . '.' . $m . '.' . $d;
break;
case 'dd/mm/yyyy':
$date[0] = $d . '/' . $m . '/' . $y;
break;
case 'mm/dd/yyyy':
$date[0] = $m . '/' . $d . '/' . $y;
break;
case 'yyyy/mm/dd':
$date[0] = $y . '/' . $m . '/' . $d;
break;
default:
break;
}

if (isset($date[1]) && '' != $date[1]) {
$userDate = $date[0] . ' ' . $date[1];
} else {
$userDate = $date[0];
}
\App\Log::trace('End ' . __METHOD__);
return $userDate;
}

/** Function to set date values compatible to database (YY_MM_DD).
* @param $user -- value :: Type Users
*
* @returns $insert_date -- insert_date :: Type string
*/
public function getDBInsertDateValue()
Expand Down Expand Up @@ -111,25 +194,6 @@ public static function convertToDBFormat($date, $user = null)
return $return;
}

/**
* @param string $date
* @param string $format
*
* @return string
*/
public static function __convertToDBFormat($date, $format)
{
if (empty($date)) {
\App\Log::trace('End ' . __METHOD__);

return $date;
}
if ('' == $format) {
$format = 'yyyy-mm-dd';
}
return \App\Fields\Date::sanitizeDbFormat($date, $format);
}

/**
* @param string $date
* @param Users $user
Expand All @@ -147,69 +211,6 @@ public static function convertToUserFormat($date)
return $userDate;
}

/**
* @param string $date
* @param string $format
*
* @return string
*/
public static function __convertToUserFormat($date, $format)
{
\App\Log::trace('Start ' . __METHOD__ . ' ' . serialize($date) . ' | ' . $format);
if (!\is_array($date)) {
$date = explode(' ', $date);
}
$separator = '-';
if (false !== strpos($date[0], '-')) {
$separator = '-';
} elseif (false !== strpos($date[0], '.')) {
$separator = '.';
} elseif (false !== strpos($date[0], '/')) {
$separator = '/';
}
[$y, $m, $d] = array_pad(explode($separator, $date[0]), 3, null);

switch ($format) {
case 'dd-mm-yyyy':
$date[0] = $d . '-' . $m . '-' . $y;
break;
case 'mm-dd-yyyy':
$date[0] = $m . '-' . $d . '-' . $y;
break;
case 'yyyy-mm-dd':
$date[0] = $y . '-' . $m . '-' . $d;
break;
case 'dd.mm.yyyy':
$date[0] = $d . '.' . $m . '.' . $y;
break;
case 'mm.dd.yyyy':
$date[0] = $m . '.' . $d . '.' . $y;
break;
case 'yyyy.mm.dd':
$date[0] = $y . '.' . $m . '.' . $d;
break;
case 'dd/mm/yyyy':
$date[0] = $d . '/' . $m . '/' . $y;
break;
case 'mm/dd/yyyy':
$date[0] = $m . '/' . $d . '/' . $y;
break;
case 'yyyy/mm/dd':
$date[0] = $y . '/' . $m . '/' . $d;
break;
default:
break;
}

if (isset($date[1]) && '' != $date[1]) {
$userDate = $date[0] . ' ' . $date[1];
} else {
$userDate = $date[0];
}
\App\Log::trace('End ' . __METHOD__);
return $userDate;
}

/**
* @param string $value
* @param Users $user
Expand All @@ -221,7 +222,7 @@ public static function convertToUserTimeZone($value, $user = null)
if (empty($user)) {
$user = $current_user;
}
$timeZone = \is_object($user) ? $user->time_zone : App\Config::main('default_timezone');
$timeZone = \is_object($user) ? $user->get('time_zone') : App\Config::main('default_timezone');
$return = self::convertTimeZone($value, App\Fields\DateTime::getTimeZone(), $timeZone);
\App\Log::trace('End ' . __METHOD__);
return $return;
Expand Down Expand Up @@ -326,7 +327,7 @@ public function getDisplayTime($user = null, bool $convertTimeZone = true, bool
$date = new DateTime($this->datetime);
}
$time = $fullTime ? $date->format('H:i:s') : $date->format('H:i');
//Convert time to user preferred value
// Convert time to user preferred value
if ('12' === \App\User::getCurrentUserModel()->getDetail('hour_format')) {
$time = Vtiger_Time_UIType::getTimeValueInAMorPM($time);
}
Expand All @@ -343,6 +344,11 @@ public function getFullcalenderTime($user = null)
return $time;
}

public function getFullcalenderValue($user = null)
{
return self::convertToUserTimeZone($this->datetime, $user)->format('Y-m-d') . ' ' . $this->getFullcalenderTime($user);
}

/**
* Sanitize date.
*
Expand All @@ -362,9 +368,4 @@ private static function sanitizeDate(string $value, $user): string
$value = str_replace('T', ' ', $value);
return \App\Fields\DateTime::sanitizeDbFormat($value, $user->getDetail('date_format'));
}

public function getFullcalenderValue($user = null)
{
return self::convertToUserTimeZone($this->datetime, $user)->format('Y-m-d') . ' ' . $this->getFullcalenderTime($user);
}
}
6 changes: 4 additions & 2 deletions include/runtime/cache/Connectors.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@

class Vtiger_Cache_Connector_Memory
{
protected $values = [];

public function set($key, $value)
{
$this->$key = $value;
$this->values[$key] = $value;
}

public function get($key)
{
return $this->$key ?? false;
return $this->values[$key] ?? false;
}

public function flush()
Expand Down
Loading

0 comments on commit d3e2a71

Please sign in to comment.