-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
66 changed files
with
4,728 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Carbon\Carbon; | ||
use Illuminate\Console\Command; | ||
use App\Jobs\SynchronizeAddressBooks; | ||
use App\Models\Account\AddressBookSubscription; | ||
|
||
class DavClientsUpdate extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'monica:davclients'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Update all dav subscriptions'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
$subscriptions = AddressBookSubscription::active()->get(); | ||
|
||
$now = now(); | ||
$subscriptions->filter(function ($subscription) use ($now) { | ||
return $this->isTimeToRunSync($subscription, $now); | ||
})->each(function ($subscription) { | ||
SynchronizeAddressBooks::dispatch($subscription); | ||
}); | ||
} | ||
|
||
/** | ||
* Test if the last synchronized timestamp is older than the subscription's frequency time. | ||
* | ||
* @param AddressBookSubscription $subscription | ||
* @param Carbon $now | ||
* @return bool | ||
*/ | ||
private function isTimeToRunSync(AddressBookSubscription $subscription, Carbon $now): bool | ||
{ | ||
return is_null($subscription->last_synchronized_at) | ||
|| $subscription->last_synchronized_at->addMinutes($subscription->frequency)->lessThan($now); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\User\User; | ||
use Illuminate\Console\Command; | ||
use App\Services\DavClient\CreateAddressBookSubscription; | ||
|
||
class NewAddressBookSubscription extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'monica:newaddressbooksubscription | ||
{--email= : Monica account to add subscription to} | ||
{--url= : CardDAV url of the address book} | ||
{--login= : Login} | ||
{--password= : Password of the account}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Add a new all dav subscriptions'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
$user = User::where('email', $this->option('email'))->firstOrFail(); | ||
|
||
$url = $this->option('url') ?? $this->ask('url', 'CardDAV url of the address book'); | ||
$login = $this->option('login') ?? $this->ask('login', 'Login name'); | ||
$password = $this->option('password') ?? $this->ask('password', 'User password'); | ||
|
||
try { | ||
$addressBook = app(CreateAddressBookSubscription::class)->execute([ | ||
'account_id' => $user->account_id, | ||
'user_id' => $user->id, | ||
'base_uri' => $url, | ||
'username' => $login, | ||
'password' => $password, | ||
]); | ||
} catch (\Exception $e) { | ||
$this->error($e->getMessage()); | ||
} | ||
|
||
if (! isset($addressBook)) { | ||
$this->error('Could not add subscription'); | ||
} else { | ||
$this->info('Subscription added'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.