Skip to content

Commit

Permalink
Use static callers for formatTime, humanify, and validDate methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mastacontrola committed Jan 1, 2017
1 parent ff86c83 commit 8ad5ea1
Show file tree
Hide file tree
Showing 22 changed files with 71 additions and 73 deletions.
3 changes: 1 addition & 2 deletions packages/service/lib/service_lib.php
Expand Up @@ -44,11 +44,10 @@
*/
function Service_Log_message($logpath, $name, $msg)
{
global $FOGCore;
$logfile = fopen($logpath, "a");
$msg = sprintf(
"[%s] %s %s\n",
$FOGCore->formatTime('now', 'm-d-y g:i:s a'),
FOGCore::formatTime('now', 'm-d-y g:i:s a'),
$name,
$msg
);
Expand Down
4 changes: 2 additions & 2 deletions packages/web/lib/client/snapinclient.class.php
Expand Up @@ -28,7 +28,7 @@ class SnapinClient extends FOGClient implements FOGClientSend
*/
public function json()
{
$date = $this->formatTime('', 'Y-m-d H:i:s');
$date = self::formatTime('', 'Y-m-d H:i:s');
$HostName = $this->Host->get('name');
$Task = $this->Host->get('task');
$SnapinJob = $this->Host->get('snapinjob');
Expand Down Expand Up @@ -214,7 +214,7 @@ public function json()
*/
public function send()
{
$date = $this->formatTime('', 'Y-m-d H:i:s');
$date = self::formatTime('', 'Y-m-d H:i:s');
$HostName = $this->Host->get('name');
$Task = $this->Host->get('task');
$SnapinJob = $this->Host->get('snapinjob');
Expand Down
22 changes: 11 additions & 11 deletions packages/web/lib/fog/fogbase.class.php
Expand Up @@ -958,13 +958,13 @@ public static function niceDate($date = 'now', $utc = false)
*
* @return mixed
*/
public function formatTime($time, $format = false, $utc = false)
public static function formatTime($time, $format = false, $utc = false)
{
if (!$time instanceof DateTime) {
$time = self::niceDate($time, $utc);
}
if ($format) {
if (!$this->validDate($time)) {
if (!self::validDate($time)) {
return _('No Data');
}

Expand All @@ -977,7 +977,7 @@ public function formatTime($time, $format = false, $utc = false)
if (is_nan($diff)) {
return _('Not a number');
}
if (!$this->validDate($time)) {
if (!self::validDate($time)) {
return _('No Data');
}
$date = $time->format('Y/m/d');
Expand All @@ -987,9 +987,9 @@ public function formatTime($time, $format = false, $utc = false)
} elseif ($diff < 0 && $absolute < 60) {
return 'Seconds from now';
} elseif ($absolute < 3600) {
return $this->humanify($diff / 60, 'minute');
return self::humanify($diff / 60, 'minute');
} else {
return $this->humanify($diff / 3600, 'hour');
return self::humanify($diff / 3600, 'hour');
}
}
$dayAgo = clone $now;
Expand All @@ -1001,14 +1001,14 @@ public function formatTime($time, $format = false, $utc = false)
} elseif ($dayAhead->format('Y/m/d') == $date) {
return 'Runs today at '.$time->format('H:i');
} elseif ($absolute / 86400 <= 7) {
return $this->humanify($diff / 86400, 'day');
return self::humanify($diff / 86400, 'day');
} elseif ($absolute / 604800 <= 5) {
return $this->humanify($diff / 604800, 'week');
return self::humanify($diff / 604800, 'week');
} elseif ($absolute / 2628000 < 12) {
return $this->humanify($diff / 2628000, 'month');
return self::humanify($diff / 2628000, 'month');
}

return $this->humanify($diff / 31536000, 'year');
return self::humanify($diff / 31536000, 'year');
}
/**
* Checks if the time passed is valid or not.
Expand All @@ -1018,7 +1018,7 @@ public function formatTime($time, $format = false, $utc = false)
*
* @return object
*/
protected function validDate($date, $format = '')
protected static function validDate($date, $format = '')
{
if ($format == 'N') {
if ($date instanceof DateTime) {
Expand Down Expand Up @@ -1170,7 +1170,7 @@ protected function diff($start, $end, $ago = false)
*
* @return string
*/
protected function humanify($diff, $unit)
protected static function humanify($diff, $unit)
{
if (!is_numeric($diff)) {
throw new Exception(_('Diff parameter must be numeric'));
Expand Down
6 changes: 3 additions & 3 deletions packages/web/lib/fog/fogcontroller.class.php
Expand Up @@ -475,8 +475,8 @@ public function save()
}
break;
case 'createdTime':
if (!($val && $this->validDate($val))) {
$val = $this->formatTime('now', 'Y-m-d H:i:s');
if (!($val && self::validDate($val))) {
$val = self::formatTime('now', 'Y-m-d H:i:s');
}
break;
case 'id':
Expand Down Expand Up @@ -1083,7 +1083,7 @@ public function setQuery(&$queryData)
(array) $this->data,
(array) $classData
);
foreach ((array)$this->databaseFieldClassRelationships as $class => &$fields) {
foreach ($this->databaseFieldClassRelationships as $class => &$fields) {
$class = self::getClass($class);
$this->set(
$fields[2],
Expand Down
2 changes: 1 addition & 1 deletion packages/web/lib/fog/fogpage.class.php
Expand Up @@ -2326,7 +2326,7 @@ public function kernelfetch()
'%s%s_%s',
$backuppath,
$destfile,
$this->formatTime('', 'Ymd_His')
self::formatTime('', 'Ymd_His')
);
list(
$tftpPass,
Expand Down
2 changes: 1 addition & 1 deletion packages/web/lib/fog/reportmaker.class.php
Expand Up @@ -258,7 +258,7 @@ public function outputReport($intType = 0)
global $FOGCore;
$backup_name = sprintf(
'fog_backup_%s.sql',
$FOGCore->formatTime('', 'Ymd_His')
self::formatTime('', 'Ymd_His')
);
$SchemaSave->exportdb($backup_name);
unset($SchemaSave);
Expand Down
2 changes: 1 addition & 1 deletion packages/web/lib/fog/schema.class.php
Expand Up @@ -188,7 +188,7 @@ public function exportdb(
if (!$backup_name) {
$backup_name = sprintf(
'fog_backup_%s.sql',
$this->formatTime('', 'Ymd_His')
self::formatTime('', 'Ymd_His')
);
}
$dump = self::getClass('Mysqldump');
Expand Down
2 changes: 1 addition & 1 deletion packages/web/lib/fog/snapintaskmanager.class.php
Expand Up @@ -100,7 +100,7 @@ public function cancel($snapintaskids)
'',
array(
'stateID' => $cancelled,
'complete'=>$this->formatTime('', 'Y-m-d H:i:s')
'complete'=> self::formatTime('', 'Y-m-d H:i:s')
)
);
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/web/lib/fog/system.class.php
Expand Up @@ -53,7 +53,7 @@ private static function _versionCompare()
public function __construct()
{
self::_versionCompare();
define('FOG_VERSION', '82');
define('FOG_VERSION', '100');
define('FOG_SCHEMA', 244);
define('FOG_BCACHE_VER', 111);
define('FOG_SVN_REVISION', 6052);
Expand Down
2 changes: 1 addition & 1 deletion packages/web/lib/fog/task.class.php
Expand Up @@ -211,7 +211,7 @@ public function cancel()
'',
array(
'clients' => 0,
'completetime' => $this->formatTime('now', 'Y-m-d H:i:s'),
'completetime' => self::formatTime('now', 'Y-m-d H:i:s'),
'stateID' => $this->getCancelledState()
)
);
Expand Down
4 changes: 2 additions & 2 deletions packages/web/lib/pages/groupmanagementpage.class.php
Expand Up @@ -670,7 +670,7 @@ public function edit()
$this->data[] = array(
'snapin_id' => $Snapin->get('id'),
'snapin_name' => $Snapin->get('name'),
'snapin_created' => $this->formatTime(
'snapin_created' => self::formatTime(
$Snapin->get('createdTime'),
'Y-m-d H:i:s'
),
Expand Down Expand Up @@ -1488,7 +1488,7 @@ public function deletehosts()
$this->data[] = array(
'host_name' => $Host->get('name'),
'host_mac' => $Host->get('mac'),
'host_deployed' => $this->formatTime(
'host_deployed' => self::formatTime(
$Host->get('deployed'),
'Y-m-d H:i:s'
),
Expand Down
12 changes: 6 additions & 6 deletions packages/web/lib/pages/hostmanagementpage.class.php
Expand Up @@ -261,7 +261,7 @@ public function __construct($name = '')
}
$this->data[] = array(
'id' => $Host->get('id'),
'deployed' => $this->formatTime(
'deployed' => self::formatTime(
$Host->get('deployed'),
'Y-m-d H:i:s'
),
Expand Down Expand Up @@ -2018,7 +2018,7 @@ public function edit()
}
$start = $log->get('start');
$end = $log->get('finish');
if (!$this->validDate($start) || !$this->validDate($end)) {
if (!self::validDate($start) || !self::validDate($end)) {
continue;
}
$diff = $this->diff($start, $end);
Expand Down Expand Up @@ -2131,24 +2131,24 @@ public function edit()
}
$start = self::niceDate($SnapinTask->get('checkin'));
$end = self::niceDate($SnapinTask->get('complete'));
if (!$this->validDate($start)) {
if (!self::validDate($start)) {
continue;
}
if (!in_array($SnapinTask->get('stateID'), $doneStates)) {
$diff = _('Snapin task not completed');
} elseif (!$this->validDate($end)) {
} elseif (!self::validDate($end)) {
$diff = _('No complete time recorded');
} else {
$diff = $this->diff($start, $end);
}
$this->data[] = array(
'snapin_name' => $Snapin->get('name'),
'snapin_start' => $this->formatTime(
'snapin_start' => self::formatTime(
$SnapinTask->get('checkin'), 'Y-m-d H:i:s'
),
'snapin_end' => sprintf(
'<span class="icon" title="%s">%s</span>',
$this->formatTime(
self::formatTime(
$SnapinTask->get('complete'), 'Y-m-d H:i:s'
),
self::getClass(
Expand Down
8 changes: 4 additions & 4 deletions packages/web/lib/pages/imagemanagementpage.class.php
Expand Up @@ -342,8 +342,8 @@ public function __construct($name = '')
* If the date is valid format in Y-m-d H:i:s
* and if not set to no valid data.
*/
if ($this->validDate($date)) {
$date = $this->formatTime($date, 'Y-m-d H:i:s');
if (self::validDate($date)) {
$date = self::formatTime($date, 'Y-m-d H:i:s');
} else {
$date = _('No valid data');
}
Expand Down Expand Up @@ -1268,7 +1268,7 @@ public function multicast()
'mc_count' => $MulticastSession->get('sessclients'),
'image_name' => $Image->get('name'),
'os' => $Image->getOS()->get('name'),
'mc_start' => $this->formatTime(
'mc_start' => self::formatTime(
$MulticastSession->get('starttime'),
'Y-m-d H:i:s'
),
Expand Down Expand Up @@ -1350,7 +1350,7 @@ public function multicastPost()
->set('stateID', 0)
->set('sessclients', $_REQUEST['count'])
->set('isDD', $Image->get('imageTypeID'))
->set('starttime', $this->formatTime('now', 'Y-m-d H:i:s'))
->set('starttime', self::formatTime('now', 'Y-m-d H:i:s'))
->set('interface', $StorageNode->get('interface'))
->set('logpath', $Image->get('path'))
->set('storagegroupID', $StorageNode->get('id'))
Expand Down

0 comments on commit 8ad5ea1

Please sign in to comment.