Skip to content

Commit

Permalink
Merge pull request #631
Browse files Browse the repository at this point in the history
* pr-631:
  [Core,Jobs] failed tests
  [Core,Jobs] fixed failed jobs pagination filter, ref #628
  [Core,Applications] fixed failed application attachment upload, ref #629
  [Organization] fixed OrganizationImage::metadata default value to be null.
  integrated phpunit into github actions
  [Docker] removed --small-files option for mongodb server
  [Core] added ability to load additional module during development, ref #613
  [Core] fixed mail service path options for FileTransport
  [Applications] fixed deprecated php each function
  [Core] fixed RatingFieldset getter properties, ref #626
  [Core] fixed tz_date data type conversion, ref #627
  • Loading branch information
TiSiE committed Feb 25, 2021
2 parents 681e591 + c4b5867 commit dc8fc42
Show file tree
Hide file tree
Showing 18 changed files with 161 additions and 49 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: CI

on:
push:
pull_request:

env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERAGE: '0'
APPLICATION_ENV: 'development'
TIMEZONE: Europe/Berlin

jobs:
phpunit:
name: PHPUnit Test
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
matrix:
php:
- '7.4'
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: pecl, composer
extensions: intl, bcmath, curl, openssl, mbstring, mongodb, solr
coverage: pcov
ini-values: memory_limit=-1
- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.3.0
with:
mongodb-version: 4.4
- name: Copy CI Configuration
run: |
cp etc/travis/autoload/*.* config/autoload
- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Set Composer platform config
if: (startsWith(matrix.php, '8.0'))
run: |
composer config platform.php 7.4.99
- name: Update project dependencies
run: composer update --no-interaction --no-progress --ansi
- name: Run PHPUnit tests
run: |
mkdir -p build/logs/phpunit
if [ "$COVERAGE" = '1' ]; then
vendor/bin/phpunit --coverage-clover build/logs/phpunit/clover.xml --log-junit build/logs/phpunit/junit.xml
else
vendor/bin/phpunit --log-junit build/logs/phpunit/junit.xml
fi
- name: Upload test artifacts
if: always()
uses: actions/upload-artifact@v1
with:
name: phpunit-logs-php${{ matrix.php }}
path: build/logs/phpunit
continue-on-error: true
- name: Upload coverage results to Codecov
if: matrix.coverage
uses: codecov/codecov-action@v1
with:
name: phpunit-php${{ matrix.php }}
flags: phpunit
fail_ci_if_error: true
continue-on-error: true
- name: Upload coverage results to Coveralls
if: matrix.coverage
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
composer global require --prefer-dist --no-interaction --no-progress --ansi cedx/coveralls
export PATH="$PATH:$HOME/.composer/vendor/bin"
coveralls build/logs/phpunit/clover.xml
wget https://scrutinizer-ci.com/ocular.phar
travis_retry php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml
continue-on-error: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ config/phpdoc.xml
config/autoload
config/autoload.bak
config/autoload/*.php
!config/autoload/.gitkeep

test/config/*.local.php
test/TestConfig.php
Expand Down
Empty file added config/autoload/.gitkeep
Empty file.
17 changes: 12 additions & 5 deletions config/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
* @license MIT
*/

if (getenv('ADDITIONAL_MODULES')) {

}

return [
$modules = [
'SlmQueue',
'Core',
'Auth',
Expand All @@ -26,3 +22,14 @@
'ReleaseTools',
'Yawik\\Migration'
];

// add ability to load additional module in autoload/*.module.php
use Symfony\Component\Finder\Finder;
$finder = Finder::create()
->name('*.module.php')
->in(__DIR__.'/autoload');
foreach($finder->files() as $file){
$modules = array_merge($modules, include $file);
}

return $modules;
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ services:
- ./etc/docker/mongodb/data:/data/db
ports:
- "27017:27017"
command: mongod --smallfiles --logpath=/dev/null # --quiet
command: mongod --logpath=/dev/null # --quiet
10 changes: 7 additions & 3 deletions module/Applications/src/Controller/ManageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,13 @@ public function statusAction()
$form = $this->forms->get('Applications/Mail');
$form->populateValues($params);



$recipient = $params['to'];
$to = $params['to'];
$email = key($to);
$name = $to[$email];
$recipient = [
'email' => $email,
'name' => $name,
];

return [
'recipient' => $recipient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class UpdateFilesPermissionsSubscriber implements EventSubscriber
*
* @see \Doctrine\Common\EventSubscriber::getSubscribedEvents()
*/
public function getSubscribedEvents()
public function getSubscribedEvents(): array
{
return array(Events::onFlush);
}
Expand Down Expand Up @@ -54,8 +54,10 @@ public function onFlush(OnFlushEventArgs $eventArgs)
foreach ($documents as $document) { /* @var \Applications\Entity\Application $document */
$permissions = $document->getPermissions();

foreach ($document->getAttachments() as $attachment) { /* @var \Applications\Entity\Attachment $attachment */
$attachment->getPermissions()
foreach ($document->getAttachments() as $attachment) {
/* @var \Applications\Entity\Attachment $attachment */
$attachment->getMetadata()
->getPermissions()
->clear()
->inherit($permissions);
if ($isUpdate) {
Expand All @@ -67,9 +69,10 @@ public function onFlush(OnFlushEventArgs $eventArgs)
}

if ($image = $document->getContact()->getImage()) {
$image->getPermissions()
->clear()
->inherit($permissions);
$image->getMetadata()
->getPermissions()
->clear()
->inherit($permissions);
if ($isUpdate) {
$uow->computeChangeSet(
$dm->getClassMetadata(get_class($image)),
Expand Down
4 changes: 3 additions & 1 deletion module/Applications/src/Service/UploadHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ private function doUploadFile(
$metadata->setContentType($info['type']);
$metadata->setName($info['name']);

$this->dm->persist($user);
if(!is_null($user)){
$this->dm->persist($user);
}
return $fileManager->uploadFromFile(
Attachment::class,
$metadata,
Expand Down
7 changes: 1 addition & 6 deletions module/Applications/view/applications/manage/status.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ $form->get('mailText')->setAttribute('style', 'height: 250px');
?>
<div>
<?php
list ($email, $name) = each ($recipient);
if (is_int($email)) {
$email = $name;
$name = '';
}

echo sprintf($this->translate("To") . ': ' . '"%s" &lt;%s&gt;<br>', $name, $email);
echo sprintf($this->translate("To") . ': ' . '"%s" &lt;%s&gt;<br>', $recipient['name'], $recipient['email']);

?>
</div>
Expand Down
6 changes: 1 addition & 5 deletions module/Core/src/Entity/FileMetadataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@ interface FileMetadataInterface extends ResourceInterface
{
public function getName(): ?string;

public function setUser(UserInterface $user);
public function setUser(?UserInterface $user): self;

public function getUser(): ?UserInterface;

public function setPermissions(PermissionsInterface $permissions);

public function getPermissions(): ?PermissionsInterface;

/**
* @param string $contentType
* @return self
*/
public function setContentType(string $contentType);

public function getContentType(): ?string;
Expand Down
6 changes: 5 additions & 1 deletion module/Core/src/Entity/FileMetadataTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public function getContentType(): ?string
return $this->contentType;
}

/**
* @param string|null $contentType
* @return $this
*/
public function setContentType(?string $contentType)
{
$this->contentType = $contentType;
Expand All @@ -62,7 +66,7 @@ public function getUser(): ?UserInterface
return $this->user;
}

public function setUser(UserInterface $user)
public function setUser(?UserInterface $user): self
{
if ($this->user) {
$this->getPermissions()->revoke($this->user, Permissions::PERMISSION_ALL, false);
Expand Down
8 changes: 7 additions & 1 deletion module/Core/src/Form/RatingFieldset.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ public function build()

foreach ($properties as $property) {
$name = $property->getName();
if (0 === strpos($name, '-')) {

// @TODO: check if '-' check is necessary
if (
0 === strpos($name, '-')
|| 0 === strpos($name, '_')
) {
continue;
}

$value = $rating->{'get' . $name}();
$input = array(
'type' => 'Core/Rating',
Expand Down
7 changes: 6 additions & 1 deletion module/Core/src/Mail/MailServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ public function getTransport(MailServiceOptions $mailServiceOptions)
return new Smtp($mailServiceOptions);
} elseif (MailService::TRANSPORT_FILE == $type) {
$fileOptions = new FileOptions();
$fileOptions->setPath($mailServiceOptions->getPath());
$path = $mailServiceOptions->getPath();
if(!is_dir($path)){
mkdir($path, true);
}

$fileOptions->setPath($path);
return new FileTransport($fileOptions);
} elseif (MailService::TRANSPORT_SENDMAIL == $type) {
return new Sendmail();
Expand Down
23 changes: 11 additions & 12 deletions module/Core/src/Paginator/Adapter/DoctrineMongoLateAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ class DoctrineMongoLateAdapter implements AdapterInterface
*/
private QueryBuilder $queryBuilder;

/**
* @var AbstractPaginationQuery
*/
private AbstractPaginationQuery $filter;

private array $params;
private $totalItem;

/**
* @param QueryBuilder $queryBuilder
Expand All @@ -38,8 +33,15 @@ class DoctrineMongoLateAdapter implements AdapterInterface
public function __construct(QueryBuilder $queryBuilder, AbstractPaginationQuery $filter, $params = array())
{
$this->queryBuilder = $queryBuilder;
$this->filter = $filter;
$this->params = $params;
$filtered = $filter->createQuery($params, $queryBuilder);
$this->queryBuilder = $queryBuilder;

// skip count during tests
if(!is_null($filtered)){
$this->queryBuilder = $filtered;
$this->totalItem = (clone $filtered)->count()->getQuery()->execute();
}

}

public function getItems($offset, $itemCountPerPage)
Expand All @@ -55,13 +57,10 @@ public function getItems($offset, $itemCountPerPage)

/**
* @return int
* @throws \Doctrine\ODM\MongoDB\MongoDBException
* FIXME: count method for ODM Module 3
*/
public function count()
{
$qb = clone $this->queryBuilder;
return $qb->count()->getQuery()->execute();
return $this->totalItem;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ public function closureToPhp(): string
/* CODE FROM: ' . __METHOD__ . ' */
if (!is_array($value)
|| !isset($value["date"])
|| !$value["date"] instanceOf UTCDateTime
|| is_null($value["date"])
|| !isset($value["tz"])
) {
$return = null;
} else {
$date = new \DateTime("@".$value["date"]->sec);
//$date = new \DateTime($value["date"]);
$date = $value["date"]->toDateTime();
$date->setTimezone(new \DateTimeZone($value["tz"]));
$return = $date;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public function createQuery($params, $queryBuilder)
*/
if (isset($params['search']) && !empty($params['search'])) {
$search = strtolower($params['search']);
$expression = $queryBuilder->expr()->operator('$text', ['$search' => $search]);
$queryBuilder->field(null)->equals($expression->getQuery());
$queryBuilder->text($search);
}
if (isset($params['o']) && !empty($params['o'])) {
$queryBuilder->field('organization')->equals(new ObjectId($params['o']));
Expand Down
5 changes: 3 additions & 2 deletions module/Jobs/src/Repository/Filter/PaginationQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ public function createQuery($params, $queryBuilder)
*/
if (isset($params['search']) && !empty($params['search'])) {
$search = strtolower($params['search']);
$expression = $queryBuilder->expr()->operator('$text', ['$search' => $search]);
$queryBuilder->field(null)->equals($expression->getQuery());
//$expression = $queryBuilder->expr()->operator('$text', ['$search' => $search]);
//$queryBuilder->field(null)->equals($expression->getQuery());
$queryBuilder->text($search);
}
if (isset($params['o']) && !empty($params['o'])) {
$queryBuilder->field('organization')->equals(new ObjectId($params['o']));
Expand Down
2 changes: 1 addition & 1 deletion module/Organizations/src/Entity/OrganizationImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class OrganizationImage implements ImageInterface
/**
* @ODM\File\Metadata(targetDocument="Organizations\Entity\OrganizationImageMetadata")
*/
protected ?ImageMetadata $metadata;
protected ?ImageMetadata $metadata = null;

public function getMetadata(): ?ImageMetadata
{
Expand Down

0 comments on commit dc8fc42

Please sign in to comment.