Skip to content

Commit

Permalink
Merge pull request #41094 from nextcloud/fix/indirect-safe-dep
Browse files Browse the repository at this point in the history
fix(dav): Remove usage of indirect thecodingmachine/safe dependency
  • Loading branch information
Pytal authored Oct 25, 2023
2 parents 2e25247 + 5281623 commit 460954a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
16 changes: 8 additions & 8 deletions apps/dav/lib/UserMigration/CalendarMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace OCA\DAV\UserMigration;

use function Safe\substr;
use function substr;
use OCA\DAV\AppInfo\Application;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin;
Expand All @@ -50,7 +50,6 @@
use Sabre\VObject\Property\ICalendar\DateTime;
use Sabre\VObject\Reader as VObjectReader;
use Sabre\VObject\UUIDUtil;
use Safe\Exceptions\StringsException;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;
Expand Down Expand Up @@ -185,12 +184,13 @@ function (ICalendar $calendar) use ($user, $output) {

private function getUniqueCalendarUri(IUser $user, string $initialCalendarUri): string {
$principalUri = $this->getPrincipalUri($user);
try {
$initialCalendarUri = substr($initialCalendarUri, 0, strlen(CalendarMigrator::MIGRATED_URI_PREFIX)) === CalendarMigrator::MIGRATED_URI_PREFIX
? $initialCalendarUri
: CalendarMigrator::MIGRATED_URI_PREFIX . $initialCalendarUri;
} catch (StringsException $e) {
throw new CalendarMigratorException('Failed to get unique calendar URI', 0, $e);

$initialCalendarUri = substr($initialCalendarUri, 0, strlen(CalendarMigrator::MIGRATED_URI_PREFIX)) === CalendarMigrator::MIGRATED_URI_PREFIX
? $initialCalendarUri
: CalendarMigrator::MIGRATED_URI_PREFIX . $initialCalendarUri;

if ($initialCalendarUri === '') {
throw new CalendarMigratorException('Failed to get unique calendar URI');
}

$existingCalendarUris = array_map(
Expand Down
27 changes: 12 additions & 15 deletions apps/dav/lib/UserMigration/ContactsMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

namespace OCA\DAV\UserMigration;

use function Safe\sort;
use function Safe\substr;
use function sort;
use function substr;
use OCA\DAV\AppInfo\Application;
use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\CardDAV\Plugin as CardDAVPlugin;
Expand All @@ -46,8 +46,6 @@
use Sabre\VObject\Reader as VObjectReader;
use Sabre\VObject\Splitter\VCard as VCardSplitter;
use Sabre\VObject\UUIDUtil;
use Safe\Exceptions\ArrayException;
use Safe\Exceptions\StringsException;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;
Expand Down Expand Up @@ -165,12 +163,12 @@ function (array $addressBookInfo) use ($user, $output) {
private function getUniqueAddressBookUri(IUser $user, string $initialAddressBookUri): string {
$principalUri = $this->getPrincipalUri($user);

try {
$initialAddressBookUri = substr($initialAddressBookUri, 0, strlen(ContactsMigrator::MIGRATED_URI_PREFIX)) === ContactsMigrator::MIGRATED_URI_PREFIX
? $initialAddressBookUri
: ContactsMigrator::MIGRATED_URI_PREFIX . $initialAddressBookUri;
} catch (StringsException $e) {
throw new ContactsMigratorException('Failed to get unique address book URI', 0, $e);
$initialAddressBookUri = substr($initialAddressBookUri, 0, strlen(ContactsMigrator::MIGRATED_URI_PREFIX)) === ContactsMigrator::MIGRATED_URI_PREFIX
? $initialAddressBookUri
: ContactsMigrator::MIGRATED_URI_PREFIX . $initialAddressBookUri;

if ($initialAddressBookUri === '') {
throw new ContactsMigratorException('Failed to get unique address book URI');
}

$existingAddressBookUris = array_map(
Expand Down Expand Up @@ -303,11 +301,10 @@ private function getAddressBookImports(array $importFiles): array {
fn (string $filename) => pathinfo($filename, PATHINFO_EXTENSION) === ContactsMigrator::METADATA_EXT,
);

try {
sort($addressBookImports);
sort($metadataImports);
} catch (ArrayException $e) {
throw new ContactsMigratorException('Failed to sort address book files in ' . ContactsMigrator::PATH_ROOT, 0, $e);
$addressBookSort = sort($addressBookImports);
$metadataSort = sort($metadataImports);
if ($addressBookSort === false || $metadataSort === false) {
throw new ContactsMigratorException('Failed to sort address book files in ' . ContactsMigrator::PATH_ROOT);
}

if (count($addressBookImports) !== count($metadataImports)) {
Expand Down

0 comments on commit 460954a

Please sign in to comment.