Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelRobitaille committed Sep 26, 2024
1 parent 0d9bc82 commit 7ff34b5
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 50 deletions.
23 changes: 15 additions & 8 deletions lib/BackgroundJob/ImportCalendarJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,30 @@

class ImportCalendarJob extends TimedJob {

private $service;
private GoogleCalendarAPIService $service;

public function __construct(ITimeFactory $timeFactory, GoogleCalendarAPIService $service) {
parent::__construct($timeFactory);
$this->service = $service;
parent::setInterval(1);
}

protected function run($arguments): void {
echo(date("Y-m-d H:i:s") . ' Importing ' . $arguments['cal_name'] . '...');
/**
* @param array{user_id: string, cal_id: string, cal_name: string,color: string} $argument
*/
protected function run($argument): void {
echo(date("Y-m-d H:i:s") . ' Importing ' . $argument['cal_name'] . '...');
$result = $this->service->safeImportCalendar(
$arguments['user_id'],
$arguments['cal_id'],
$arguments['cal_name'],
$arguments['color'],
$argument['user_id'],
$argument['cal_id'],
$argument['cal_name'],
$argument['color'],
);
echo(' done. Added ' . $result['nbAdded'] . PHP_EOL);
if (isset($result['error'])) {
echo(' error: ' . $result['error'] . PHP_EOL);
} else {
echo(' done. Added ' . $result['nbAdded'] . PHP_EOL);
}
}

}
21 changes: 9 additions & 12 deletions lib/Controller/GoogleAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,14 @@ public function getCalendarList(): DataResponse {
if ($this->accessToken === '' || $this->userId === null) {
return new DataResponse([], 400);
}
/** @var array{error?:string} $result */
/** @var array{error?:array{id: string}} $result */
$result = $this->googleCalendarAPIService->getCalendarList($this->userId);
if (isset($result['error'])) {
$response = new DataResponse($result['error'], 401);
} else {
foreach ($result as $key => $cal) {
$isJobRegistered = $this->googleCalendarAPIService->
isJobRegisteredForCalendar($this->userId, $cal["id"]);
$calId = $cal["id"];
$result[$key]["isJobRegistered"] = $isJobRegistered;
}
$response = new DataResponse($result);
Expand Down Expand Up @@ -227,12 +226,12 @@ public function importCalendar(string $calId, string $calName, ?string $color =
* @return DataResponse
*/
public function registerSyncCalendar(string $calId, string $calName, ?string $color = null): DataResponse {
if ($this->accessToken === '') {
if ($this->accessToken === '' || $this->userId === null) {
return new DataResponse('', 400);
}
$result = $this->googleCalendarAPIService->registerSyncCalendar(
$this->googleCalendarAPIService->registerSyncCalendar(
$this->userId, $calId, $calName, $color);
$response = new DataResponse($result, 200);
$response = new DataResponse("OK", 200);
return $response;
}

Expand All @@ -245,14 +244,12 @@ public function registerSyncCalendar(string $calId, string $calName, ?string $co
* @return DataResponse
*/
public function unregisterSyncCalendar(string $calId): DataResponse {

$accessToken = $this->accessToken;
$userId = $this->userId;


$result = $this->googleCalendarAPIService->unregisterSyncCalendar(
if ($this->accessToken === '' || $this->userId === null) {
return new DataResponse('', 400);
}
$this->googleCalendarAPIService->unregisterSyncCalendar(
$this->userId, $calId);
$response = new DataResponse($result, 200);
$response = new DataResponse("OK", 200);
return $response;
}

Expand Down
6 changes: 5 additions & 1 deletion lib/Service/GoogleAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,16 @@ public function simpleRequest(string $userId, string $url, array $params = [], s

/**
* Make a simple authenticated HTTP request to download a file
*
* @param string $userId the user from which the request is coming
* @param string $url The path to reach
* @param resource $resource
* @param array $params Query parameters (key/val pairs)
* @param string $method HTTP query method
* @return string[]
*
* @return (mixed|string|true)[]
*
* @psalm-return array{error?: mixed|string, success?: true}
*/
public function simpleDownload(string $userId, string $url, $resource, array $params = [], string $method = 'GET'): array {
$this->checkTokenExpiration($userId);
Expand Down
26 changes: 13 additions & 13 deletions lib/Service/GoogleCalendarAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@

namespace OCA\Google\Service;

use Ds\Set;
use DateTime;
use DateTimeZone;
use Ds\Set;
use Exception;
use Generator;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\Google\AppInfo\Application;
use OCP\IL10N;
use OCP\BackgroundJob\IJobList;
use OCA\Google\BackgroundJob\ImportCalendarJob;
use OCP\BackgroundJob\IJobList;
use OCP\IL10N;

use Ortic\ColorConverter\Color;
use Ortic\ColorConverter\Colors\Named;
Expand Down Expand Up @@ -86,7 +86,6 @@ private function getClosestCssColor(string $hexColor): string {
];
// init
$closestColor = 'black';
/** @var Color $color */
$black = Color::fromString(Named::CSS_COLORS['black']);
$rgbBlack = [
'r' => $black->getRed(),
Expand All @@ -96,7 +95,6 @@ private function getClosestCssColor(string $hexColor): string {
$closestDiff = $this->colorDiff($rbgColor, $rgbBlack);

foreach (Named::CSS_COLORS as $name => $hex) {
/** @var Color $color */
$c = Color::fromString($hex);
$rgb = [
'r' => $c->getRed(),
Expand Down Expand Up @@ -170,7 +168,7 @@ private function getCalendarLastEventModificationTimestamp(int $calendarId): int
* @param string $calId
* @param string $calName
* @param ?string $color
* @return array
* @return array{error: string}|array{nbAdded: int, nbUpdated: int, calName: string}
*/
public function safeImportCalendar(string $userId, string $calId, string $calName, ?string $color = null): array {
$startTime = microtime(true);
Expand Down Expand Up @@ -201,7 +199,7 @@ public function safeImportCalendar(string $userId, string $calId, string $calNam
* @param string $calId
* @param string $calName
* @param ?string $color
* @return array
* @return array{nbAdded: int, nbUpdated: int, calName: string}
*/
public function importCalendar(string $userId, string $calId, string $calName, ?string $color = null): array {
$params = [];
Expand All @@ -216,13 +214,16 @@ public function importCalendar(string $userId, string $calId, string $calName, ?
$ncCalId = $this->caldavBackend->createCalendar('principals/users/' . $userId, $newCalName, $params);
}

/** @var Set<string> $unseenURIs */
$unseenURIs = new Set();
/** @var array{uri: string} $e */
foreach ($this->caldavBackend->getCalendarObjects($ncCalId) as $e) {
$unseenURIs->add($e['uri']);
}

// get color list
$eventColors = [];
/** @type array{error: string}|array{event: array} $colors */
$colors = $this->googleApiService->request($userId, 'calendar/v3/colors');
if (!isset($colors['error']) && isset($colors['event'])) {
$eventColors = $colors['event'];
Expand Down Expand Up @@ -385,7 +386,7 @@ public function importCalendar(string $userId, string $calId, string $calName, ?

$eventGeneratorReturn = $events->getReturn();
if (isset($eventGeneratorReturn['error'])) {
return $eventGeneratorReturn;
/* return $eventGeneratorReturn; */
}
return [
'nbAdded' => $nbAdded,
Expand All @@ -405,7 +406,7 @@ public function resetRegisteredSyncCalendar(): void {
* Check if a background job is registered.
* @param string $userId The user id of the job.
* @param string $calId The calendar id of the job.
* @return Whether the job with the given parameters is registered.
* @return bool Whether the job with the given parameters is registered.
*/
public function isJobRegisteredForCalendar(string $userId, string $calId): bool {
foreach ($this->jobList->getJobsIterator(ImportCalendarJob::class, null, 0) as $job) {
Expand All @@ -426,7 +427,7 @@ public function isJobRegisteredForCalendar(string $userId, string $calId): bool
* @param string $calId
* @param string $calName
* @param ?string $color
* @return array
* @return void
*/
public function registerSyncCalendar(string $userId, string $calId, string $calName, ?string $color = null): void {
$argument = [
Expand All @@ -437,7 +438,6 @@ public function registerSyncCalendar(string $userId, string $calId, string $calN
];

foreach ($this->jobList->getJobsIterator(ImportCalendarJob::class, null, 0) as $job) {
$id = $job->getId();
$args = $job->getArgument();

if ($args["user_id"] == $argument["user_id"] && $args["cal_id"] == $argument["cal_id"]) {
Expand All @@ -456,12 +456,12 @@ public function registerSyncCalendar(string $userId, string $calId, string $calN
* @param string $calId
* @param string $calName
* @param ?string $color
* @return array
* @return void
*/
public function unregisterSyncCalendar(string $userId, string $calId): void {

foreach ($this->jobList->getJobsIterator(ImportCalendarJob::class, null, 0) as $job) {
$id = $job->getId();
/** @var array{user_id: string, cal_id: string} $args */
$args = $job->getArgument();

if ($args["user_id"] == $userId && $args["cal_id"] == $calId) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/GoogleContactsAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ public function importContacts(string $userId, ?string $uri, int $key, ?string $
// group/label
if (isset($c['memberships']) && is_array($c['memberships'])) {
$contactGroupNames = [];
/** @var array{contactGroupMembership: array{contactGroupResourceName: mixed}} $membership */
foreach ($c['memberships'] as $membership) {
/** @var array{contactGroupMembership: array{contactGroupResourceName: mixed}} $membership */
foreach ($c['memberships'] as $membership) {
if (isset(
$membership['contactGroupMembership'],
$membership['contactGroupMembership']['contactGroupResourceName'],
Expand Down
1 change: 0 additions & 1 deletion lib/Service/GoogleDriveAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use OCP\BackgroundJob\IJobList;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\ForbiddenException;
use OCP\Files\InvalidPathException;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/GooglePhotosAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ private function getPhoto(string $userId, array $photo, Folder $albumFolder): ?i
$stat = $savedFile->stat();
return intval($stat['size'] ?? 0);
} else {
$this->logger->warning('Google API error downloading photo ' . '<redacted>' . ' : ' . $res['error'], ['app' => Application::APP_ID]);
$this->logger->warning('Google API error downloading photo ' . '<redacted>' . ' : ' . (string)$res['error'], ['app' => Application::APP_ID]);
if ($savedFile->isDeletable()) {
$savedFile->unlock(ILockingProvider::LOCK_EXCLUSIVE);
$savedFile->delete();
Expand Down
2 changes: 1 addition & 1 deletion src/components/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export default {
axios.delete(generateUrl('/apps/google_synchronization/reset-sync-calendar'))
.then(() => {
showSuccess(
this.n('google_synchronization', 'Successfully deleted background jobs', 'Successfully deleted background jobs', 1)
this.n('google_synchronization', 'Successfully deleted background jobs', 'Successfully deleted background jobs', 1),
)
})
.catch((error) => {
Expand Down
22 changes: 11 additions & 11 deletions src/components/PersonalSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ export default {
const ssoWindow = window.open(
requestUrl,
t('google_synchronization', 'Sign in with Google'),
'toolbar=no, menubar=no, width=600, height=700'
'toolbar=no, menubar=no, width=600, height=700',
)
ssoWindow.focus()
window.addEventListener('message', (event) => {
Expand Down Expand Up @@ -586,7 +586,7 @@ export default {
.catch((error) => {
showServerError(
error,
t('google_synchronization', 'Failed to get number of Google photos')
t('google_synchronization', 'Failed to get number of Google photos'),
)
})
.then(() => {
Expand Down Expand Up @@ -650,8 +650,8 @@ export default {
'{nbSeen} Google contact seen. {nbAdded} added, {nbUpdated} updated in {name}',
'{nbSeen} Google contacts seen. {nbAdded} added, {nbUpdated} updated in {name}',
nbSeen,
{ nbAdded, nbSeen, nbUpdated, name: this.selectedAddressBookName }
)
{ nbAdded, nbSeen, nbUpdated, name: this.selectedAddressBookName },
),
)
this.showAddressBooks = false
})
Expand Down Expand Up @@ -688,8 +688,8 @@ export default {
'{total} event successfully imported in {name} ({nbAdded} created, {nbUpdated} updated)',
'{total} events successfully imported in {name} ({nbAdded} created, {nbUpdated} updated)',
total,
{ total, nbAdded, nbUpdated, name: calName }
)
{ total, nbAdded, nbUpdated, name: calName },
),
)
})
.catch((error) => {
Expand Down Expand Up @@ -722,7 +722,7 @@ export default {
.then((_response) => {
cal.isJobRegistered = desiredState
showSuccess(
this.n('google_synchronization', successMessage, successMessage, 1)
this.n('google_synchronization', successMessage, successMessage, 1),
)
})
.catch((error) => {
Expand All @@ -746,7 +746,7 @@ export default {
.then((response) => {
const targetPath = response.data.targetPath
showSuccess(
t('google_synchronization', 'Starting importing photos in {targetPath} directory', { targetPath })
t('google_synchronization', 'Starting importing photos in {targetPath} directory', { targetPath }),
)
this.getPhotoImportValues(true)
})
Expand Down Expand Up @@ -812,7 +812,7 @@ export default {
.then((response) => {
const targetPath = response.data.targetPath
showSuccess(
t('google_synchronization', 'Starting importing files in {targetPath} directory', { targetPath })
t('google_synchronization', 'Starting importing files in {targetPath} directory', { targetPath }),
)
this.getDriveImportValues(true)
})
Expand Down Expand Up @@ -874,7 +874,7 @@ export default {
},
false,
'httpd/unix-directory',
true
true,
)
},
onPhotoOutputChange() {
Expand All @@ -889,7 +889,7 @@ export default {
},
false,
'httpd/unix-directory',
true
true,
)
},
},
Expand Down

0 comments on commit 7ff34b5

Please sign in to comment.