public static function markAsStopped($serviceName, $id) { $logPath = Yii::getPathOfAlias('root.assets.services.stopped.' . $serviceName . ".log"); $initPath = Yii::getPathOfAlias('root.assets.services.stopped.' . $serviceName . ".init"); if (!is_dir($logPath)) { mkdir($logPath, 0777, true); } if (!is_dir($initPath)) { mkdir($initPath, 0777, true); } $oldLog = ServiceManager::getLogPath($serviceName, $id); $oldInit = Yii::getPathOfAlias('root.assets.services.init') . DIRECTORY_SEPARATOR . $id; if (is_file($oldLog) && is_file($oldInit)) { self::saveStoppedLog($serviceName, $id, $initPath, $oldInit); self::saveStoppedLog($serviceName, $id, $logPath, $oldLog); } }
public static function markAsStopped($serviceName, $id) { $path = Yii::getPathOfAlias('root.assets.services.stopped.' . $serviceName); $new = $path . DIRECTORY_SEPARATOR . $id; if (!is_dir($path)) { mkdir($path, 0777, true); } $old = ServiceManager::getLogPath($serviceName, $id); if (is_file($old)) { $initPath = Yii::getPathOfAlias('root.assets.services.init'); $init = $initPath . DIRECTORY_SEPARATOR . $id; if (is_file($init)) { unlink($init); } ## only retain maximum 30 logs $logs = glob($path . DIRECTORY_SEPARATOR . "*"); natsort($logs); $logs = array_values($logs); $count = count($logs); $file = str_replace($path . DIRECTORY_SEPARATOR, "", $new); if ($count > 0) { $count = explode(".", str_replace($path . DIRECTORY_SEPARATOR, "", $logs[$count - 1]))[0]; } $new = $path . DIRECTORY_SEPARATOR . ($count + 1) . "." . $file; rename($old, $new); if ($count > 30) { unlink($logs[0]); } } }