Skip to content

Commit

Permalink
Support php 8.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
areksolek committed Sep 13, 2023
1 parent 3e21356 commit 3a22aa4
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 65 deletions.
60 changes: 31 additions & 29 deletions modules/Vtiger/models/TreeInventoryModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,37 @@ class Vtiger_TreeInventoryModal_Model extends Vtiger_TreeCategoryModal_Model
* @var bool Auto register events
*/
public $autoRegisterEvents = false;
/** @var int Last id in tree. */
private $lastTreeId;

/** {@inheritdoc} */
public static function getInstance(Vtiger_Module_Model $moduleModel)
{
$moduleName = $moduleModel->get('name');
$modelClassName = Vtiger_Loader::getComponentClassName('Model', 'TreeInventoryModal', $moduleName);
$instance = new $modelClassName();
$instance->set('module', $moduleModel)->set('moduleName', $moduleName);
return $instance;
}

/**
* Retrieves all records and categories.
*
* @return array
*/
public function getTreeData()
{
$treeData = [];
$treeList = $this->getTreeList();
$records = $this->getRecords();
foreach ($records as $tree) {
while (isset($treeList[$tree['parent']]) && !\in_array($treeList[$tree['parent']], $treeData)) {
$tree = $treeList[$tree['parent']];
$treeData[] = $tree;
}
}
return array_merge($treeData, $records);
}

/**
* Creates a tree for records.
Expand Down Expand Up @@ -84,33 +115,4 @@ private function getTreeList()
$this->lastTreeId = $lastId;
return $trees;
}

/** {@inheritdoc} */
public static function getInstance(Vtiger_Module_Model $moduleModel)
{
$moduleName = $moduleModel->get('name');
$modelClassName = Vtiger_Loader::getComponentClassName('Model', 'TreeInventoryModal', $moduleName);
$instance = new $modelClassName();
$instance->set('module', $moduleModel)->set('moduleName', $moduleName);
return $instance;
}

/**
* Retrieves all records and categories.
*
* @return array
*/
public function getTreeData()
{
$treeData = [];
$treeList = $this->getTreeList();
$records = $this->getRecords();
foreach ($records as $tree) {
while (isset($treeList[$tree['parent']]) && !\in_array($treeList[$tree['parent']], $treeData)) {
$tree = $treeList[$tree['parent']];
$treeData[] = $tree;
}
}
return array_merge($treeData, $records);
}
}
43 changes: 26 additions & 17 deletions modules/com_vtiger_workflow/tasks/VTCreateEventTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,6 @@ public function doTask($recordModel)
}
}

private function calculateDate($recordModel, $days, $direction, $datefield)
{
$baseDate = $recordModel->get($datefield);
if ('' == $baseDate) {
$baseDate = date('Y-m-d');
}
if ('' == $days) {
$days = 0;
}
preg_match('/\d\d\d\d-\d\d-\d\d/', $baseDate, $match);
$baseDate = strtotime($match[0]);
return strftime('%Y-%m-%d', $baseDate + $days * 24 * 60 * 60 *
('before' == strtolower($direction) ? -1 : 1));
}

/**
* To convert time_start & time_end values to db format.
*
Expand All @@ -132,8 +117,7 @@ public static function convertToDBFormat($timeStr)
{
$date = new DateTime();
$time = \App\Fields\Time::sanitizeDbFormat($timeStr);
$dbInsertDateTime = DateTimeField::convertToDBTimeZone($date->format('Y-m-d') . ' ' . $time);

$dbInsertDateTime = DateTimeField::convertToDBTimeZone(App\Fields\Date::formatToDisplay($date->format('Y-m-d')) . ' ' . $time);
return $dbInsertDateTime->format('H:i:s');
}

Expand All @@ -153,4 +137,29 @@ public function getTimeFieldList()
{
return ['startTime', 'endTime'];
}

/**
* Calculate date.
*
* @param Vtiger_Record_Model $recordModel
* @param int $days
* @param string $direction
* @param string $datefield
*
* @return string
*/
private function calculateDate(Vtiger_Record_Model $recordModel, int $days, string $direction, string $datefield): string
{
$baseDate = $recordModel->get($datefield);
if ('' == $baseDate) {
$baseDate = date('Y-m-d');
}
if ('' == $days) {
$days = 0;
}
preg_match('/\d\d\d\d-\d\d-\d\d/', $baseDate, $match);
$days = $days + ('before' === strtolower($direction) ? -1 : 1);
$baseDate = new DateTime($match[0]);
return $baseDate->modify("+ $days days")->format('Y-m-d');
}
}
24 changes: 12 additions & 12 deletions modules/com_vtiger_workflow/tasks/VTCreateTodoTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,16 @@ public function doTask($recordModel)
$time = explode(' ', $baseDateStart);
if (\count($time) < 2) {
$timeWithSec = \App\Fields\Time::sanitizeDbFormat($this->time);
$dbInsertDateTime = DateTimeField::convertToDBTimeZone($baseDateStart . ' ' . $timeWithSec);
$dbInsertDateTime = DateTimeField::convertToDBTimeZone(App\Fields\Date::formatToDisplay($baseDateStart) . ' ' . $timeWithSec);
$time = $dbInsertDateTime->format('H:i:s');
} else {
$time = $time[1];
}
preg_match('/\d\d\d\d-\d\d-\d\d/', $baseDateStart, $match);
$baseDateStart = strtotime($match[0]);
$date_start = strftime('%Y-%m-%d', $baseDateStart + (int) $this->days_start * 24 * 60 * 60 * ('before' == strtolower($this->direction_start) ? -1 : 1));
$endIncrement = \App\Fields\Double::formatToDb($this->days_end) * 24 * 60 * 60 * ('before' == strtolower($this->direction_end) ? -1 : 1);
$baseDateStart = new DateTime($match[0]);
$daysStart = (int) $this->days_start + ('before' === strtolower($this->direction_start) ? -1 : 1);
$dateStart = $baseDateStart->modify("+ $daysStart days")->format('Y-m-d');
$endIncrement = \App\Fields\Double::formatToDb($this->days_end) + ('before' == strtolower($this->direction_end) ? -1 : 1);

if ('fromDateStart' !== $this->datefield_end) {
if ('wfRunTime' == $this->datefield_end) {
Expand All @@ -123,21 +124,20 @@ public function doTask($recordModel)
$timeEnd = \App\User::getUserModel(\App\User::getActiveAdminId())->getDetail('end_hour');
}
$timeWithSec = \App\Fields\Time::sanitizeDbFormat($timeEnd);
$dbInsertDateTime = DateTimeField::convertToDBTimeZone($baseDateEnd . ' ' . $timeWithSec);
$dbInsertDateTime = DateTimeField::convertToDBTimeZone(App\Fields\Date::formatToDisplay($baseDateEnd) . ' ' . $timeWithSec);
$timeEnd = $dbInsertDateTime->format('H:i:s');
} else {
$timeEnd = $timeEnd[1];
}
preg_match('/\d\d\d\d-\d\d-\d\d/', $baseDateEnd, $match);
$baseDateEnd = strtotime($match[0]);
$due_date = strftime('%Y-%m-%d ', $baseDateEnd + $endIncrement);
$baseDateEnd = new DateTime($match[0]);
$dueDate = $baseDateEnd->modify("+ $endIncrement days")->format('Y-m-d');
} else {
$dueDateTime = date('Y-m-d H:i:s', strtotime($date_start . ' ' . $time) + $endIncrement);
$dueDateTime = date('Y-m-d H:i:s', strtotime($dateStart . ' ' . $time) + $endIncrement);
$dueDateTime = explode(' ', $dueDateTime);
$due_date = $dueDateTime[0];
$dueDate = $dueDateTime[0];
$timeEnd = $dueDateTime[1];
}

$textParser = \App\TextParser::getInstanceByModel($recordModel);
$fields = [
'activitytype' => 'Task',
Expand All @@ -149,8 +149,8 @@ public function doTask($recordModel)
'time_start' => $time,
'time_end' => $timeEnd,
'sendnotification' => ('' != $this->sendNotification && 'N' != $this->sendNotification),
'date_start' => $date_start,
'due_date' => $due_date,
'date_start' => $dateStart,
'due_date' => $dueDate,
'visibility' => 'Private',
'meeting_url' => $this->meetingUrl ?? '',
];
Expand Down
15 changes: 8 additions & 7 deletions modules/com_vtiger_workflow/tasks/VTUpdateCalendarDates.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public function doTask($recordModel)
}
}
preg_match('/\d\d\d\d-\d\d-\d\d/', $baseDateStart, $match);
$baseDateStart = strtotime($match[0]);
$baseDateStart = new DateTime($match[0]);
$daysStart = $task['days_start'] + ('before' === strtolower($task['direction_start']) ? -1 : 1);
$dateStart = $baseDateStart->modify("+ $daysStart days")->format('Y-m-d');

if ('wfRunTime' === $task['datefield_end']) {
$baseDateEnd = date('Y-m-d H:i:s');
Expand All @@ -65,13 +67,12 @@ public function doTask($recordModel)
}
}
preg_match('/\d\d\d\d-\d\d-\d\d/', $baseDateEnd, $match);
$baseDateEnd = strtotime($match[0]);
$baseDateEnd = new DateTime($match[0]);
$daysEnd = $task['days_end'] + ('before' === strtolower($task['direction_start']) ? -1 : 1);
$duedate = $baseDateEnd->modify("+ $daysEnd days")->format('Y-m-d');

$date_start = strftime('%Y-%m-%d', $baseDateStart + $task['days_start'] * 24 * 60 * 60 * ('before' == strtolower($task['direction_start']) ? -1 : 1));
$due_date = strftime('%Y-%m-%d', $baseDateEnd + $task['days_end'] * 24 * 60 * 60 * ('before' == strtolower($task['direction_start']) ? -1 : 1));

$rowRecordModel->set('date_start', $date_start);
$rowRecordModel->set('due_date', $due_date);
$rowRecordModel->set('date_start', $dateStart);
$rowRecordModel->set('due_date', $duedate);
$rowRecordModel->save();
}
}
Expand Down

0 comments on commit 3a22aa4

Please sign in to comment.