Skip to content

Commit

Permalink
Merge pull request #46605 from nextcloud/bugfix/noid/test-more-oracle…
Browse files Browse the repository at this point in the history
…-versions

fix(deps): Deprecate functionality deprecated by doctrine and test on more oracle versions
  • Loading branch information
nickvergessen authored Jul 19, 2024
2 parents 8f975cd + b656edc commit 7395211
Show file tree
Hide file tree
Showing 38 changed files with 304 additions and 237 deletions.
30 changes: 16 additions & 14 deletions .github/workflows/phpunit-oci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,21 @@ jobs:
runs-on: ubuntu-latest

needs: changes
if: needs.changes.outputs.src != 'false' && ${{ github.repository_owner != 'nextcloud-gmbh' }}
if: ${{ needs.changes.outputs.src != 'false' && github.repository_owner != 'nextcloud-gmbh' }}

strategy:
fail-fast: false
matrix:
oracle-versions: ['11']
php-versions: ['8.1', '8.2', '8.3']
include:
- php-versions: '8.3'
- oracle-versions: '11'
php-versions: '8.1'
- oracle-versions: '18'
php-versions: '8.1'
coverage: ${{ github.event_name != 'pull_request' }}
- oracle-versions: '21'
php-versions: '8.2'
- oracle-versions: '23'
php-versions: '8.3'

name: Oracle ${{ matrix.oracle-versions }} (PHP ${{ matrix.php-versions }}) - database tests

Expand All @@ -71,23 +77,21 @@ jobs:
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3

oracle:
image: ghcr.io/gvenzl/oracle-xe:${{ matrix.oracle-versions }}
image: ghcr.io/gvenzl/oracle-${{ matrix.oracle-versions < 23 && 'xe' || 'free' }}:${{ matrix.oracle-versions }}

# Provide passwords and other environment variables to container
env:
ORACLE_RANDOM_PASSWORD: true
APP_USER: oc_autotest
APP_USER_PASSWORD: nextcloud
ORACLE_PASSWORD: oracle

# Forward Oracle port
ports:
- 4444:1521/tcp
- 1521:1521

# Provide healthcheck script options for startup
options: >-
--health-cmd healthcheck.sh
--health-interval 10s
--health-timeout 5s
--health-interval 20s
--health-timeout 10s
--health-retries 10
steps:
Expand All @@ -111,13 +115,11 @@ jobs:
run: composer i

- name: Set up Nextcloud
env:
DB_PORT: 4444
run: |
mkdir data
cp tests/redis.config.php config/
cp tests/preseed-config.php config/config.php
./occ maintenance:install --verbose --database=oci --database-name=XE --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=oc_autotest --database-pass=nextcloud --admin-user admin --admin-pass admin
./occ maintenance:install --verbose --database=oci --database-name=${{ matrix.oracle-versions < 23 && 'XE' || 'FREE' }} --database-host=127.0.0.1 --database-port=1521 --database-user=system --database-pass=oracle --admin-user admin --admin-pass admin
php -f tests/enable_all.php | grep -i -C9999 error && echo "Error during app setup" && exit 1 || exit 0
- name: PHPUnit
Expand Down
20 changes: 12 additions & 8 deletions apps/contactsinteraction/lib/Db/CardSearchDao.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,37 @@ public function findExisting(IUser $user,
$cardQuery = $this->db->getQueryBuilder();
$propQuery = $this->db->getQueryBuilder();

$propOr = $propQuery->expr()->orX();
$additionalWheres = [];
if ($uid !== null) {
$propOr->add($propQuery->expr()->andX(
$additionalWheres[] = $propQuery->expr()->andX(
$propQuery->expr()->eq('name', $cardQuery->createNamedParameter('UID')),
$propQuery->expr()->eq('value', $cardQuery->createNamedParameter($uid))
));
);
}
if ($email !== null) {
$propOr->add($propQuery->expr()->andX(
$additionalWheres[] = $propQuery->expr()->andX(
$propQuery->expr()->eq('name', $cardQuery->createNamedParameter('EMAIL')),
$propQuery->expr()->eq('value', $cardQuery->createNamedParameter($email))
));
);
}
if ($cloudId !== null) {
$propOr->add($propQuery->expr()->andX(
$additionalWheres[] = $propQuery->expr()->andX(
$propQuery->expr()->eq('name', $cardQuery->createNamedParameter('CLOUD')),
$propQuery->expr()->eq('value', $cardQuery->createNamedParameter($cloudId))
));
);
}
$addressbooksQuery->selectDistinct('id')
->from('addressbooks')
->where($addressbooksQuery->expr()->eq('principaluri', $cardQuery->createNamedParameter("principals/users/" . $user->getUID())));
$propQuery->selectDistinct('cardid')
->from('cards_properties')
->where($propQuery->expr()->in('addressbookid', $propQuery->createFunction($addressbooksQuery->getSQL()), IQueryBuilder::PARAM_INT_ARRAY))
->andWhere($propOr)
->groupBy('cardid');

if (!empty($additionalWheres)) {
$propQuery->andWhere($propQuery->expr()->orX(...$additionalWheres));
}

$cardQuery->select('carddata')
->from('cards')
->where($cardQuery->expr()->in('id', $cardQuery->createFunction($propQuery->getSQL()), IQueryBuilder::PARAM_INT_ARRAY))
Expand Down
14 changes: 8 additions & 6 deletions apps/contactsinteraction/lib/Db/RecentContactMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,25 @@ public function findMatch(IUser $user,
?string $cloudId): array {
$qb = $this->db->getQueryBuilder();

$or = $qb->expr()->orX();
$additionalWheres = [];
if ($uid !== null) {
$or->add($qb->expr()->eq('uid', $qb->createNamedParameter($uid)));
$additionalWheres[] = $qb->expr()->eq('uid', $qb->createNamedParameter($uid));
}
if ($email !== null) {
$or->add($qb->expr()->eq('email', $qb->createNamedParameter($email)));
$additionalWheres[] = $qb->expr()->eq('email', $qb->createNamedParameter($email));
}
if ($cloudId !== null) {
$or->add($qb->expr()->eq('federated_cloud_id', $qb->createNamedParameter($cloudId)));
$additionalWheres[] = $qb->expr()->eq('federated_cloud_id', $qb->createNamedParameter($cloudId));
}

$select = $qb
->select('*')
->from($this->getTableName())
->where($or)
->andWhere($qb->expr()->eq('actor_uid', $qb->createNamedParameter($user->getUID())));
->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($user->getUID())));

if (!empty($additionalWheres)) {
$select->andWhere($select->expr()->orX(...$additionalWheres));
}
return $this->findEntities($select);
}

Expand Down
64 changes: 34 additions & 30 deletions apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -1875,12 +1875,12 @@ public function search(
}

if (!empty($searchProperties)) {
$or = $innerQuery->expr()->orX();
$or = [];
foreach ($searchProperties as $searchProperty) {
$or->add($innerQuery->expr()->eq('op.name',
$outerQuery->createNamedParameter($searchProperty)));
$or[] = $innerQuery->expr()->eq('op.name',
$outerQuery->createNamedParameter($searchProperty));
}
$innerQuery->andWhere($or);
$innerQuery->andWhere($innerQuery->expr()->orX(...$or));
}

if ($pattern !== '') {
Expand Down Expand Up @@ -1924,12 +1924,12 @@ public function search(
}

if (!empty($options['types'])) {
$or = $outerQuery->expr()->orX();
$or = [];
foreach ($options['types'] as $type) {
$or->add($outerQuery->expr()->eq('componenttype',
$outerQuery->createNamedParameter($type)));
$or[] = $outerQuery->expr()->eq('componenttype',
$outerQuery->createNamedParameter($type));
}
$outerQuery->andWhere($or);
$outerQuery->andWhere($outerQuery->expr()->orX(...$or));
}

$outerQuery->andWhere($outerQuery->expr()->in('c.id', $outerQuery->createFunction($innerQuery->getSQL())));
Expand Down Expand Up @@ -2150,67 +2150,71 @@ public function searchPrincipalUri(string $principalUri,
$escapePattern = !\array_key_exists('escape_like_param', $options) || $options['escape_like_param'] !== false;

$calendarObjectIdQuery = $this->db->getQueryBuilder();
$calendarOr = $calendarObjectIdQuery->expr()->orX();
$searchOr = $calendarObjectIdQuery->expr()->orX();
$calendarOr = [];
$searchOr = [];

// Fetch calendars and subscription
$calendars = $this->getCalendarsForUser($principalUri);
$subscriptions = $this->getSubscriptionsForUser($principalUri);
foreach ($calendars as $calendar) {
$calendarAnd = $calendarObjectIdQuery->expr()->andX();
$calendarAnd->add($calendarObjectIdQuery->expr()->eq('cob.calendarid', $calendarObjectIdQuery->createNamedParameter((int)$calendar['id'])));
$calendarAnd->add($calendarObjectIdQuery->expr()->eq('cob.calendartype', $calendarObjectIdQuery->createNamedParameter(self::CALENDAR_TYPE_CALENDAR)));
$calendarAnd = $calendarObjectIdQuery->expr()->andX(
$calendarObjectIdQuery->expr()->eq('cob.calendarid', $calendarObjectIdQuery->createNamedParameter((int)$calendar['id'])),
$calendarObjectIdQuery->expr()->eq('cob.calendartype', $calendarObjectIdQuery->createNamedParameter(self::CALENDAR_TYPE_CALENDAR)),
);

// If it's shared, limit search to public events
if (isset($calendar['{http://owncloud.org/ns}owner-principal'])
&& $calendar['principaluri'] !== $calendar['{http://owncloud.org/ns}owner-principal']) {
$calendarAnd->add($calendarObjectIdQuery->expr()->eq('co.classification', $calendarObjectIdQuery->createNamedParameter(self::CLASSIFICATION_PUBLIC)));
}

$calendarOr->add($calendarAnd);
$calendarOr[] = $calendarAnd;
}
foreach ($subscriptions as $subscription) {
$subscriptionAnd = $calendarObjectIdQuery->expr()->andX();
$subscriptionAnd->add($calendarObjectIdQuery->expr()->eq('cob.calendarid', $calendarObjectIdQuery->createNamedParameter((int)$subscription['id'])));
$subscriptionAnd->add($calendarObjectIdQuery->expr()->eq('cob.calendartype', $calendarObjectIdQuery->createNamedParameter(self::CALENDAR_TYPE_SUBSCRIPTION)));
$subscriptionAnd = $calendarObjectIdQuery->expr()->andX(
$calendarObjectIdQuery->expr()->eq('cob.calendarid', $calendarObjectIdQuery->createNamedParameter((int)$subscription['id'])),
$calendarObjectIdQuery->expr()->eq('cob.calendartype', $calendarObjectIdQuery->createNamedParameter(self::CALENDAR_TYPE_SUBSCRIPTION)),
);

// If it's shared, limit search to public events
if (isset($subscription['{http://owncloud.org/ns}owner-principal'])
&& $subscription['principaluri'] !== $subscription['{http://owncloud.org/ns}owner-principal']) {
$subscriptionAnd->add($calendarObjectIdQuery->expr()->eq('co.classification', $calendarObjectIdQuery->createNamedParameter(self::CLASSIFICATION_PUBLIC)));
}

$calendarOr->add($subscriptionAnd);
$calendarOr[] = $subscriptionAnd;
}

foreach ($searchProperties as $property) {
$propertyAnd = $calendarObjectIdQuery->expr()->andX();
$propertyAnd->add($calendarObjectIdQuery->expr()->eq('cob.name', $calendarObjectIdQuery->createNamedParameter($property, IQueryBuilder::PARAM_STR)));
$propertyAnd->add($calendarObjectIdQuery->expr()->isNull('cob.parameter'));
$propertyAnd = $calendarObjectIdQuery->expr()->andX(
$calendarObjectIdQuery->expr()->eq('cob.name', $calendarObjectIdQuery->createNamedParameter($property, IQueryBuilder::PARAM_STR)),
$calendarObjectIdQuery->expr()->isNull('cob.parameter'),
);

$searchOr->add($propertyAnd);
$searchOr[] = $propertyAnd;
}
foreach ($searchParameters as $property => $parameter) {
$parameterAnd = $calendarObjectIdQuery->expr()->andX();
$parameterAnd->add($calendarObjectIdQuery->expr()->eq('cob.name', $calendarObjectIdQuery->createNamedParameter($property, IQueryBuilder::PARAM_STR)));
$parameterAnd->add($calendarObjectIdQuery->expr()->eq('cob.parameter', $calendarObjectIdQuery->createNamedParameter($parameter, IQueryBuilder::PARAM_STR_ARRAY)));
$parameterAnd = $calendarObjectIdQuery->expr()->andX(
$calendarObjectIdQuery->expr()->eq('cob.name', $calendarObjectIdQuery->createNamedParameter($property, IQueryBuilder::PARAM_STR)),
$calendarObjectIdQuery->expr()->eq('cob.parameter', $calendarObjectIdQuery->createNamedParameter($parameter, IQueryBuilder::PARAM_STR_ARRAY)),
);

$searchOr->add($parameterAnd);
$searchOr[] = $parameterAnd;
}

if ($calendarOr->count() === 0) {
if (empty($calendarOr)) {
return [];
}
if ($searchOr->count() === 0) {
if (empty($searchOr)) {
return [];
}

$calendarObjectIdQuery->selectDistinct('cob.objectid')
->from($this->dbObjectPropertiesTable, 'cob')
->leftJoin('cob', 'calendarobjects', 'co', $calendarObjectIdQuery->expr()->eq('co.id', 'cob.objectid'))
->andWhere($calendarObjectIdQuery->expr()->in('co.componenttype', $calendarObjectIdQuery->createNamedParameter($componentTypes, IQueryBuilder::PARAM_STR_ARRAY)))
->andWhere($calendarOr)
->andWhere($searchOr)
->andWhere($calendarObjectIdQuery->expr()->orX(...$calendarOr))
->andWhere($calendarObjectIdQuery->expr()->orX(...$searchOr))
->andWhere($calendarObjectIdQuery->expr()->isNull('deleted_at'));

if ($pattern !== '') {
Expand Down
12 changes: 6 additions & 6 deletions apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -1148,20 +1148,20 @@ private function searchByAddressBookIds(array $addressBookIds,
/**
* FIXME Find a way to match only 4 last digits
* BDAY can be --1018 without year or 20001019 with it
* $bDayOr = $query2->expr()->orX();
* $bDayOr = [];
* if ($options['since'] instanceof DateTimeFilter) {
* $bDayOr->add(
* $bDayOr[] =
* $query2->expr()->gte('SUBSTR(cp_bday.value, -4)',
* $query2->createNamedParameter($options['since']->get()->format('md')))
* $query2->createNamedParameter($options['since']->get()->format('md'))
* );
* }
* if ($options['until'] instanceof DateTimeFilter) {
* $bDayOr->add(
* $bDayOr[] =
* $query2->expr()->lte('SUBSTR(cp_bday.value, -4)',
* $query2->createNamedParameter($options['until']->get()->format('md')))
* $query2->createNamedParameter($options['until']->get()->format('md'))
* );
* }
* $query2->andWhere($bDayOr);
* $query2->andWhere($query2->expr()->orX(...$bDayOr));
*/
}

Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/DAV/CustomPropertiesBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ private function getUserProperties(string $path, array $requestedProperties) {
// request only a subset
$sql .= ' AND `propertyname` in (?)';
$whereValues[] = $requestedProperties;
$whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY;
$whereTypes[] = IQueryBuilder::PARAM_STR_ARRAY;
}

$result = $this->connection->executeQuery(
Expand Down
3 changes: 1 addition & 2 deletions apps/dav/lib/Migration/CalDAVRemoveEmptyValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
namespace OCA\DAV\Migration;

use Doctrine\DBAL\Platforms\OraclePlatform;
use OCA\DAV\CalDAV\CalDavBackend;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
Expand Down Expand Up @@ -75,7 +74,7 @@ public function run(IOutput $output) {
}

protected function getInvalidObjects($pattern) {
if ($this->db->getDatabasePlatform() instanceof OraclePlatform) {
if ($this->db->getDatabaseProvider() === IDBConnection::PLATFORM_ORACLE) {
$rows = [];
$chunkSize = 500;
$query = $this->db->getQueryBuilder();
Expand Down
4 changes: 1 addition & 3 deletions apps/settings/tests/SetupChecks/SupportedDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/
namespace OCA\Settings\Tests;

use Doctrine\DBAL\Platforms\SqlitePlatform;
use OCA\Settings\SetupChecks\SupportedDatabase;
use OCP\IDBConnection;
use OCP\IL10N;
Expand Down Expand Up @@ -41,8 +40,7 @@ protected function setUp(): void {
}

public function testPass(): void {
$platform = $this->connection->getDatabasePlatform();
if ($platform instanceof SqlitePlatform) {
if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE) {
/** SQlite always gets a warning */
$this->assertEquals(SetupResult::WARNING, $this->check->run()->getSeverity());
} else {
Expand Down
4 changes: 2 additions & 2 deletions apps/user_ldap/lib/Mapping/AbstractMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
namespace OCA\User_LDAP\Mapping;

use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use OCP\DB\IPreparedStatement;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -216,7 +216,7 @@ protected function collectResultsFromListOfIdsQuery(IQueryBuilder $qb, array &$r
public function getListOfIdsByDn(array $fdns): array {
$totalDBParamLimit = 65000;
$sliceSize = 1000;
$maxSlices = $this->dbc->getDatabasePlatform() instanceof SqlitePlatform ? 9 : $totalDBParamLimit / $sliceSize;
$maxSlices = $this->dbc->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE ? 9 : $totalDBParamLimit / $sliceSize;
$results = [];

$slice = 1;
Expand Down
4 changes: 2 additions & 2 deletions core/Command/Db/ConvertFilecacheBigInt.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/
namespace OC\Core\Command\Db;

use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Types\Type;
use OC\DB\Connection;
use OC\DB\SchemaWrapper;
use OCP\DB\Types;
use OCP\IDBConnection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -53,7 +53,7 @@ public static function getColumnsByTable(): array {

protected function execute(InputInterface $input, OutputInterface $output): int {
$schema = new SchemaWrapper($this->connection);
$isSqlite = $this->connection->getDatabasePlatform() instanceof SqlitePlatform;
$isSqlite = $this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE;
$updates = [];

$tables = static::getColumnsByTable();
Expand Down
Loading

0 comments on commit 7395211

Please sign in to comment.