mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 08:12:17 +01:00
Compare commits
1 Commits
v0.10.0
...
feature/ad
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb4d3ec061 |
@@ -22,27 +22,13 @@ class Kernel extends ConsoleKernel
|
||||
->when(fn (): bool => config('scheduling.tasks.auth_send_mails_expiring_api_tokens'))
|
||||
->everyTenMinutes();
|
||||
|
||||
if (config('app.key') && (config('scheduling.tasks.self_hosting_check_for_update') || config('scheduling.tasks.self_hosting_telemetry'))) {
|
||||
// Convert string to a stable integer for seeding
|
||||
/** @var int $seed Take the first 8 hex chars → 32-bit int */
|
||||
$seed = hexdec(substr(hash('md5', config('app.key')), 0, 8));
|
||||
$seed = abs($seed); // Ensure it's positive
|
||||
mt_srand($seed);
|
||||
$firstHour = mt_rand(0, 23);
|
||||
$secondHour = ($firstHour + 12) % 24;
|
||||
$minuteOffset = mt_rand(0, 59);
|
||||
mt_srand(null); // Reset the random number generator
|
||||
$schedule->command('self-host:check-for-update')
|
||||
->when(fn (): bool => config('scheduling.tasks.self_hosting_check_for_update'))
|
||||
->twiceDaily();
|
||||
|
||||
if (config('scheduling.tasks.self_hosting_check_for_update')) {
|
||||
$schedule->command('self-host:check-for-update')
|
||||
->twiceDailyAt($firstHour, $secondHour, $minuteOffset);
|
||||
}
|
||||
|
||||
if (config('scheduling.tasks.self_hosting_telemetry')) {
|
||||
$schedule->command('self-host:telemetry')
|
||||
->twiceDailyAt($firstHour, $secondHour, $minuteOffset);
|
||||
}
|
||||
}
|
||||
$schedule->command('self-host:telemetry')
|
||||
->when(fn (): bool => config('scheduling.tasks.self_hosting_telemetry'))
|
||||
->twiceDaily();
|
||||
|
||||
$schedule->command('self-host:database-consistency')
|
||||
->when(fn (): bool => config('scheduling.tasks.self_hosting_database_consistency'))
|
||||
|
||||
@@ -42,7 +42,7 @@ class HandleInertiaRequests extends Middleware
|
||||
$hasBilling = Module::has('Billing') && Module::isEnabled('Billing');
|
||||
$hasInvoicing = Module::has('Invoicing') && Module::isEnabled('Invoicing');
|
||||
$hasServices = Module::has('Services') && Module::isEnabled('Services');
|
||||
|
||||
|
||||
/** @var BillingContract $billing */
|
||||
$billing = app(BillingContract::class);
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
type Project,
|
||||
type TimeEntryResponse,
|
||||
} from '@/packages/api/src';
|
||||
import { getCurrentOrganizationId, getCurrentMembershipId } from '@/utils/useUser';
|
||||
import { getCurrentOrganizationId } from '@/utils/useUser';
|
||||
import { computed, ref } from 'vue';
|
||||
import { getDayJsInstance } from '@/packages/ui/src/utils/time';
|
||||
import { TimeEntryCalendar } from '@/packages/ui/src';
|
||||
@@ -73,7 +73,6 @@ const { data: timeEntryResponse, isLoading: timeEntriesLoading } = useQuery<Time
|
||||
queries: {
|
||||
start: expandedDateRange.value.start!,
|
||||
end: expandedDateRange.value.end!,
|
||||
member_id: getCurrentMembershipId(),
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -68,6 +68,19 @@ watch(
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
watch(
|
||||
() => editableTimeEntry.value?.project_id,
|
||||
(value) => {
|
||||
if (value && editableTimeEntry.value) {
|
||||
// check if project is billable by default and set billable accordingly
|
||||
const project = props.projects.find((p) => p.id === value);
|
||||
if (project) {
|
||||
editableTimeEntry.value.billable = project.is_billable;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const localStart = computed({
|
||||
get: () =>
|
||||
editableTimeEntry.value ? getLocalizedDayJs(editableTimeEntry.value.start).format() : '',
|
||||
|
||||
@@ -29,7 +29,7 @@ const open = ref(false);
|
||||
function updateTimerAndStartLiveTimerUpdate() {
|
||||
const defaultUnit =
|
||||
organizationSettings?.value?.intervalFormat === 'decimal' ? 'hours' : 'minutes';
|
||||
const seconds = parseTimeInput(temporaryCustomTimerEntry.value, defaultUnit);
|
||||
const { seconds } = parseTimeInput(temporaryCustomTimerEntry.value, defaultUnit);
|
||||
if (seconds && seconds > 0) {
|
||||
let newEndDate = props.end;
|
||||
let newStartDate = props.start;
|
||||
|
||||
@@ -56,7 +56,7 @@ const currentTime = computed({
|
||||
});
|
||||
|
||||
function updateTimerAndStartLiveTimerUpdate() {
|
||||
const seconds = parseTimeInput(temporaryCustomTimerEntry.value, 'minutes');
|
||||
const { seconds } = parseTimeInput(temporaryCustomTimerEntry.value, 'minutes');
|
||||
|
||||
if (seconds && seconds > 0) {
|
||||
const newStartDate = dayjs().subtract(seconds, 's');
|
||||
|
||||
@@ -208,30 +208,22 @@ export function formatStartEnd(
|
||||
export function parseTimeInput(
|
||||
input: string,
|
||||
defaultUnit: TimeInputUnit = 'minutes'
|
||||
): number | null {
|
||||
): {
|
||||
seconds: number | null;
|
||||
isHHMM: boolean;
|
||||
} {
|
||||
// Check if input is a decimal number (hours)
|
||||
const decimalRegex = /^-?\d+[.,]\d+$/;
|
||||
if (decimalRegex.test(input)) {
|
||||
const hours = parseFloat(input.replace(',', '.'));
|
||||
return Math.round(hours * 3600);
|
||||
return { seconds: Math.round(hours * 3600), isHHMM: false };
|
||||
}
|
||||
|
||||
// Check if input is just a number (minutes or hours based on defaultUnit)
|
||||
if (/^-?\d+$/.test(input)) {
|
||||
const value = parseInt(input);
|
||||
return defaultUnit === 'minutes' ? value * 60 : value * 3600;
|
||||
}
|
||||
|
||||
// Check if input is in HH:MM:SS format
|
||||
const HHMMSStimeRegex = /^([0-9]{1,2}):([0-5]?[0-9]):([0-5]?[0-9])$/;
|
||||
if (HHMMSStimeRegex.test(input)) {
|
||||
const match = input.match(HHMMSStimeRegex);
|
||||
if (match) {
|
||||
const hours = parseInt(match[1]);
|
||||
const minutes = parseInt(match[2]);
|
||||
const seconds = parseInt(match[3]);
|
||||
return hours * 3600 + minutes * 60 + seconds;
|
||||
}
|
||||
const seconds = defaultUnit === 'minutes' ? value * 60 : value * 3600;
|
||||
return { seconds, isHHMM: false };
|
||||
}
|
||||
|
||||
// Check if input is in HH:MM format
|
||||
@@ -241,15 +233,15 @@ export function parseTimeInput(
|
||||
if (match) {
|
||||
const hours = parseInt(match[1]);
|
||||
const minutes = parseInt(match[2]);
|
||||
return (hours * 60 + minutes) * 60;
|
||||
return { seconds: (hours * 60 + minutes) * 60, isHHMM: true };
|
||||
}
|
||||
}
|
||||
|
||||
// Try to parse natural language like "1h 30m"
|
||||
const parsedDuration = parse(input, 's');
|
||||
if (parsedDuration && parsedDuration > 0) {
|
||||
return parsedDuration;
|
||||
return { seconds: parsedDuration, isHHMM: false };
|
||||
}
|
||||
|
||||
return null;
|
||||
return { seconds: null, isHHMM: false };
|
||||
}
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Console;
|
||||
|
||||
use App\Console\Kernel;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use Tests\TestCase;
|
||||
|
||||
#[CoversClass(Kernel::class)]
|
||||
class KernelTest extends TestCase
|
||||
{
|
||||
public function test_self_host_commands_schedule_time_is_consistent_with_app_key(): void
|
||||
{
|
||||
// Arrange
|
||||
config([
|
||||
'app.key' => 'base64:cOXN4GLMXYjcdG0fKosnFogofXw1pNoXkLAViRH+a5Y=',
|
||||
]);
|
||||
|
||||
// Act
|
||||
$schedule1 = app()->make(Kernel::class)->resolveConsoleSchedule();
|
||||
$firstRunEvents = collect($schedule1->events())->filter(fn ($event) => str_contains($event->command, 'self-host:check-for-update') ||
|
||||
str_contains($event->command, 'self-host:telemetry')
|
||||
);
|
||||
|
||||
$schedule2 = app()->make(Kernel::class)->resolveConsoleSchedule();
|
||||
$secondRunEvents = collect($schedule2->events())->filter(fn ($event) => str_contains($event->command, 'self-host:check-for-update') ||
|
||||
str_contains($event->command, 'self-host:telemetry')
|
||||
);
|
||||
config([
|
||||
'app.key' => 'base64:eP58hkQ8l3guqf8wvWJR7pB0weVQtnpjMdYpaVwX4Jw=',
|
||||
]);
|
||||
$schedule3 = app()->make(Kernel::class)->resolveConsoleSchedule();
|
||||
$thirdRunEvents = collect($schedule3->events())->filter(fn ($event) => str_contains($event->command, 'self-host:check-for-update') ||
|
||||
str_contains($event->command, 'self-host:telemetry')
|
||||
);
|
||||
|
||||
// Assert
|
||||
$this->assertCount(2, $firstRunEvents);
|
||||
$this->assertCount(2, $secondRunEvents);
|
||||
$this->assertCount(2, $thirdRunEvents);
|
||||
|
||||
foreach ($firstRunEvents as $index => $event) {
|
||||
$this->assertSame('52 9,21 * * *', $firstRunEvents[$index]->expression);
|
||||
$this->assertSame('52 9,21 * * *', $secondRunEvents[$index]->expression);
|
||||
$this->assertSame('48 13,1 * * *', $thirdRunEvents[$index]->expression);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_self_hosting_telemetry_can_be_activated(): void
|
||||
{
|
||||
// Arrange
|
||||
config([
|
||||
'scheduling.tasks.self_hosting_telemetry' => true,
|
||||
]);
|
||||
|
||||
// Act
|
||||
$schedule = app()->make(Kernel::class)->resolveConsoleSchedule();
|
||||
$events = collect($schedule->events())->filter(fn ($event) => str_contains($event->command, 'self-host:telemetry')
|
||||
);
|
||||
|
||||
// Assert
|
||||
$this->assertCount(1, $events);
|
||||
}
|
||||
|
||||
public function test_self_hosting_telemetry_can_be_deactivated(): void
|
||||
{
|
||||
// Arrange
|
||||
config([
|
||||
'scheduling.tasks.self_hosting_telemetry' => false,
|
||||
]);
|
||||
|
||||
// Act
|
||||
$schedule = app()->make(Kernel::class)->resolveConsoleSchedule();
|
||||
$events = collect($schedule->events())->filter(fn ($event) => str_contains($event->command, 'self-host:telemetry')
|
||||
);
|
||||
|
||||
// Assert
|
||||
$this->assertCount(0, $events);
|
||||
}
|
||||
|
||||
public function test_self_hosting_check_for_update_can_be_activated(): void
|
||||
{
|
||||
// Arrange
|
||||
config([
|
||||
'scheduling.tasks.self_hosting_check_for_update' => true,
|
||||
]);
|
||||
|
||||
// Act
|
||||
$schedule = app()->make(Kernel::class)->resolveConsoleSchedule();
|
||||
$events = collect($schedule->events())->filter(fn ($event) => str_contains($event->command, 'self-host:check-for-update')
|
||||
);
|
||||
|
||||
// Assert
|
||||
$this->assertCount(1, $events);
|
||||
}
|
||||
|
||||
public function test_self_hosting_check_for_update_can_be_deactivated(): void
|
||||
{
|
||||
// Arrange
|
||||
config([
|
||||
'scheduling.tasks.self_hosting_check_for_update' => false,
|
||||
]);
|
||||
|
||||
// Act
|
||||
$schedule = app()->make(Kernel::class)->resolveConsoleSchedule();
|
||||
$events = collect($schedule->events())->filter(fn ($event) => str_contains($event->command, 'self-host:check-for-update')
|
||||
);
|
||||
|
||||
// Assert
|
||||
$this->assertCount(0, $events);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user