Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Umsetzung von Collection-NestedSet-Struktur mit DoctrineExtensions #227

Draft
wants to merge 27 commits into
base: doctrine
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f9144ec
#220 Converts the Collection & CollectionRole model classes to use Do…
extracts Dec 10, 2021
c0ad048
#220 Use PHP 7.2 for tests
j3nsch Jan 5, 2022
eab17e4
#220 Limit tests to CollectionTest.php
j3nsch Jan 5, 2022
c960549
Merge branch 'doctrine' of github.com:OPUS4/framework into issue220
extracts Feb 9, 2022
b307f7f
#220 For the Vagrantfile, use PHP 7.2 as required by gedmo/doctrine-e…
extracts Feb 10, 2022
e5f3f2e
#220: Updated code & package dependencies as required by gedmo/doctri…
extracts Feb 10, 2022
0218da4
Merge branch 'doctrine' of github.com:OPUS4/framework into issue220
extracts Feb 10, 2022
d08cdd3
#220 Where appropriate, use an InvalidArgumentException (instead of j…
extracts Feb 11, 2022
e453fa3
#220 Adds tree functions to set the first/last child of a Collection …
extracts Feb 11, 2022
d32a340
#220 Adds stub functions to get & set the collection's theme
extracts Feb 11, 2022
95183db
#220 Adds support for more CollectionRole database properties
extracts Feb 11, 2022
bc9df6d
#220 Adds function CollectionRole->addRootCollection() (WIP)
extracts Feb 11, 2022
8c603ab
#220 Adopts code to Doctrine's way of getting an existing Collection …
extracts Feb 11, 2022
8cb97aa
#220 CollectionTest now uses Opus\Model2\CollectionRole and adopts co…
extracts Feb 11, 2022
cc5af37
#220 Installs Xdebug to enable debugging with an IDE such as PhpStorm
extracts Feb 17, 2022
a6d7292
#220 CollectionTest->setUp() now directly persists the root collectio…
extracts Feb 17, 2022
9a4c35a
#220 Similar to e453fa3, adds more tree functions that make use of th…
extracts Feb 17, 2022
f919371
#220 The getChildren() function now always returns an array, and it u…
extracts Feb 17, 2022
c9a83d9
#220 Just adds/changes some TODOs
extracts Feb 17, 2022
f0455d5
#220 Removes code that isn't needed anymore with the Doctrine/ORM imp…
extracts Feb 17, 2022
5d59e5b
#220 Set Collection parent & children properties directly
extracts Feb 23, 2022
85ec16a
#220 Set Doctrine/ORM cascade rules for Collection and CollectionRole…
extracts Feb 23, 2022
165cadb
#220 Removes again the Doctrine/ORM cascade rules for the Collection-…
extracts Feb 24, 2022
0240557
#220 Collection->getChildren() now only returns the direct children o…
extracts Feb 24, 2022
55bb779
#220 Added a TODO about the apparent need to set Collection->roleId e…
extracts Feb 24, 2022
ab7ccb9
#220 CollectionRole->addRootCollection() now always ensures that the …
extracts Feb 24, 2022
96291e6
#220 Adds CollectionTest tests that test if deleting (or storing) the…
extracts Feb 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Setup PHP 7.1
- name: Setup PHP 7.2
uses: shivammathur/setup-php@v2
with:
php-version: '7.1'
php-version: '7.2'

- name: Update Ubuntu packages
run: sudo apt-get update
Expand All @@ -38,7 +38,7 @@ jobs:
run: ant prepare-workspace prepare-config create-database lint -DdbUserPassword=root -DdbAdminPassword=root

- name: Test
run: php composer.phar test
run: php composer.phar test tests/Opus/CollectionTest.php

- name: Coding-Style
run: php composer.phar cs-check
31 changes: 21 additions & 10 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,37 @@
# vi: set ft=ruby :

$software = <<SCRIPT
# Downgrade to PHP 7.1
# Downgrade to PHP 7.2
apt-add-repository -y ppa:ondrej/php
apt-get -yq update
apt-get -yq install php7.1
apt-get -yq install php7.2

# Install MYSQL
debconf-set-selections <<< "mysql-server mysql-server/root_password password root"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password root"
apt-get -yq install mysql-server

# Install required PHP packages
apt-get -ya install php7.1-mbstring
apt-get -yq install php7.1-dom
apt-get -yq install php7.1-pdo
apt-get -yq install php7.1-fileinfo
apt-get -yq install php7.1-json
apt-get -yq install php7.1-curl
apt-get -yq install php7.1-mysql
apt-get -yq install php7.1-zip
apt-get -ya install php7.2-mbstring
apt-get -yq install php7.2-dom
apt-get -yq install php7.2-pdo
apt-get -yq install php7.2-fileinfo
apt-get -yq install php7.2-json
apt-get -yq install php7.2-curl
apt-get -yq install php7.2-mysql
apt-get -yq install php7.2-zip

# Install Ant
apt-get -yq install ant
SCRIPT

$xdebug = <<SCRIPT
apt-get -yq install php7.2-xdebug
if ! grep "xdebug.mode=debug" /etc/php/7.2/mods-available/xdebug.ini > /dev/null; then
echo -e "xdebug.mode=debug\nxdebug.client_host=10.0.2.2\nxdebug.client_port=9003" >> /etc/php/7.2/mods-available/xdebug.ini
fi
SCRIPT

$composer = <<SCRIPT
/vagrant/bin/install-composer.sh
SCRIPT
Expand All @@ -52,6 +59,9 @@ fi
if ! grep "PATH=/vagrant/bin" /home/vagrant/.bashrc > /dev/null; then
echo "export PATH=/vagrant/bin:$PATH" >> /home/vagrant/.bashrc
fi
if ! grep "XDEBUG_SESSION=OPUS4" /home/vagrant/.bashrc > /dev/null; then
echo "export XDEBUG_SESSION=OPUS4" >> /home/vagrant/.bashrc
fi
SCRIPT

$help = <<SCRIPT
Expand All @@ -67,6 +77,7 @@ Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-20.04"

config.vm.provision "Install required software...", type: "shell", inline: $software
config.vm.provision "Install Xdebug...", type: "shell", inline: $xdebug
config.vm.provision "Install Composer...", type: "shell", privileged: false, inline: $composer
config.vm.provision "Setup database...", type: "shell", inline: $database
config.vm.provision "Prepare tests...", type: "shell", privileged: false, inline: $prepare_tests
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
"opus4-repo/opus4-common": "dev-master",
"opus4-repo/opus4-doi": "4.7.*",
"doctrine/dbal": "2.13.*",
"doctrine/orm": "2.10.*",
"doctrine/orm": "^2.10.2",
"doctrine/cache": "1.12.*",
"doctrine/annotations": "*"
"doctrine/annotations": "*",
"gedmo/doctrine-extensions": "^3.0"
},
"autoload": {
"psr-4": {
Expand All @@ -33,11 +34,11 @@
}
},
"require-dev": {
"phpunit/phpunit": "4.8.*",
"phpunit/dbunit": "~1.3",
"phpunit/phpunit": "^6.0.9",
"phpunit/dbunit": "^3.0 || ^4.0",
"behat/behat": "3.3.*",
"phpunit/php-invoker": "~1.1",
"phpunit/phpunit-selenium": "1.4.2",
"phpunit/phpunit-selenium": "^4.1.0",
"phpmd/phpmd" : "2.*",
"sebastian/phpcpd": "*",
"mayflower/php-codebrowser": "*",
Expand Down
143 changes: 143 additions & 0 deletions library/Opus/Db2/CollectionRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?php

/**
* This file is part of OPUS. The software OPUS has been originally developed
* at the University of Stuttgart with funding from the German Research Net,
* the Federal Department of Higher Education and Research and the Ministry
* of Science, Research and the Arts of the State of Baden-Wuerttemberg.
*
* OPUS 4 is a complete rewrite of the original OPUS software and was developed
* by the Stuttgart University Library, the Library Service Center
* Baden-Wuerttemberg, the Cooperative Library Network Berlin-Brandenburg,
* the Saarland University and State Library, the Saxon State Library -
* Dresden State and University Library, the Bielefeld University Library and
* the University Library of Hamburg University of Technology with funding from
* the German Research Foundation and the European Regional Development Fund.
*
* LICENCE
* OPUS is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the Licence, or any later version.
* OPUS is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. You should have received a copy of the GNU General Public License
* along with OPUS; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright Copyright (c) 2021, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

namespace Opus\Db2;

use Doctrine\ORM\ORMException;
use Gedmo\Tree\Entity\Repository\NestedTreeRepository;
use InvalidArgumentException;
use Opus\Model2\Collection;

class CollectionRepository extends NestedTreeRepository
{
/**
* Retrieve all Collection instances from the database.
*
* @return Collection[]
* @throws ORMException
*/
public function getAll()
{
return $this->findAll();
}

/**
* Returns all Collection nodes with the given role ID. Always returns an array, even if the
* result set has zero or one element.
*
* @param int $roleId The ID of the tree structure whose Collection nodes shall be returned.
* @param bool $sortResults (Optional) If true sort results by left ID.
* @return Collection[]
*/
public function fetchCollectionsByRoleId($roleId, $sortResults = false)
{
if (! isset($roleId)) {
throw new InvalidArgumentException("Parameter 'roleId' is required.");
}

$queryBuilder = $this->getEntityManager()->createQueryBuilder();

$select = $queryBuilder->select('c')
->from(Collection::class, 'c')
->where('c.roleId = :roleId')
->setParameter('roleId', $roleId);

if ($sortResults === true) {
$select->orderBy('c.left', 'ASC');
}

$query = $select->getQuery();

// TODO double check that getResult() always returns an array
return $query->getResult();
}

/**
* Returns all Collection nodes with the given role ID & name. Always returns an array, even if
* the result set has zero or one element.
*
* @param int $roleId The ID of the tree structure whose Collection nodes shall be returned.
* @param string $name
* @return Collection[]
*/
public function fetchCollectionsByRoleName($roleId, $name)
{
if (! isset($roleId)) {
throw new InvalidArgumentException("Parameter 'roleId' is required.");
}

if (! isset($name)) {
throw new InvalidArgumentException("Parameter 'name' is required.");
}

$queryBuilder = $this->getEntityManager()->createQueryBuilder();

$query = $queryBuilder->select('c')
->from(Collection::class, 'c')
->where('c.roleId = :roleId')
->andWhere('c.name = :name')
->setParameter('roleId', $roleId)
->setParameter('name', $name)
->getQuery();

// TODO double check that getResult() always returns an array
return $query->getResult();
}

/**
* Returns all child nodes of the Collection node with given ID.
*
* @param int $parentId The ID of the node whose children shall be returned.
* @param bool $sortResults (Optional) If true sort results by left ID.
* @return Collection[]
*/
public function fetchChildrenByParentId($parentId, $sortResults = false)
{
if (! isset($parentId)) {
throw new InvalidArgumentException("Parameter 'parentId' is required.");
}

$queryBuilder = $this->getEntityManager()->createQueryBuilder();

$select = $queryBuilder->select('c')
->from(Collection::class, 'c')
->where('c.parentId = :parentId')
->setParameter('parentId', $parentId);

if ($sortResults === true) {
$select->orderBy('c.left', 'ASC');
}

$query = $select->getQuery();

return $query->getResult();
}
}
66 changes: 66 additions & 0 deletions library/Opus/Db2/CollectionRoleRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

/**
* This file is part of OPUS. The software OPUS has been originally developed
* at the University of Stuttgart with funding from the German Research Net,
* the Federal Department of Higher Education and Research and the Ministry
* of Science, Research and the Arts of the State of Baden-Wuerttemberg.
*
* OPUS 4 is a complete rewrite of the original OPUS software and was developed
* by the Stuttgart University Library, the Library Service Center
* Baden-Wuerttemberg, the Cooperative Library Network Berlin-Brandenburg,
* the Saarland University and State Library, the Saxon State Library -
* Dresden State and University Library, the Bielefeld University Library and
* the University Library of Hamburg University of Technology with funding from
* the German Research Foundation and the European Regional Development Fund.
*
* LICENCE
* OPUS is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the Licence, or any later version.
* OPUS is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. You should have received a copy of the GNU General Public License
* along with OPUS; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright Copyright (c) 2021, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

namespace Opus\Db2;

use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\ORMException;
use Opus\Model2\CollectionRole;

class CollectionRoleRepository extends EntityRepository
{
/**
* Retrieve all CollectionRole instances from the database.
*
* @return CollectionRole[]
* @throws ORMException
*/
public function getAll()
{
return $this->findAll();
}

/**
* Retrieves an existing CollectionRole instance by name. Returns
* null if name is null *or* if nothing was found.
*
* @param string|null $name
* @return CollectionRole|null
*/
public function fetchByName($name = null)
{
if ($name === null) {
return null;
}

return $this->findOneBy(['name' => $name]);
}
}
Loading