Skip to content

Commit

Permalink
Downgrade PHP codebase to be compliant to PHP 7.3
Browse files Browse the repository at this point in the history
addresses #26
  • Loading branch information
SteKoe authored Jun 9, 2021
1 parent 448a77d commit da96734
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 31 deletions.
121 changes: 120 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,123 @@
FROM nextcloud
# DO NOT EDIT: created by update.sh from Dockerfile-debian.template
FROM php:7.3-apache-buster

# entrypoint.sh and cron.sh dependencies
RUN set -ex; \
\
apt-get update; \
apt-get install -y --no-install-recommends \
rsync \
bzip2 \
busybox-static \
; \
rm -rf /var/lib/apt/lists/*; \
\
mkdir -p /var/spool/cron/crontabs; \
echo '*/5 * * * * php -f /var/www/html/cron.php' > /var/spool/cron/crontabs/www-data

# install the PHP extensions we need
# see https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html
ENV PHP_MEMORY_LIMIT 512M
ENV PHP_UPLOAD_LIMIT 512M
RUN set -ex; \
\
savedAptMark="$(apt-mark showmanual)"; \
\
apt-get update; \
apt-get install -y --no-install-recommends \
libcurl4-openssl-dev \
libevent-dev \
libfreetype6-dev \
libicu-dev \
libjpeg-dev \
libldap2-dev \
libmcrypt-dev \
libmemcached-dev \
libpng-dev \
libpq-dev \
libxml2-dev \
libmagickwand-dev \
libzip-dev \
libwebp-dev \
libgmp-dev \
; \
\
debMultiarch="$(dpkg-architecture --query DEB_BUILD_MULTIARCH)"; \
docker-php-ext-install -j "$(nproc)" \
bcmath \
exif \
gd \
intl \
ldap \
opcache \
pcntl \
pdo_mysql \
pdo_pgsql \
zip \
gmp \
; \
\
# pecl will claim success even if one install fails, so we need to perform each install separately
pecl install APCu-5.1.20; \
pecl install memcached-3.1.5; \
pecl install redis-5.3.4; \
pecl install imagick-3.4.4; \
\
docker-php-ext-enable \
apcu \
memcached \
redis \
imagick \
; \
rm -r /tmp/pear; \
\
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
apt-mark auto '.*' > /dev/null; \
apt-mark manual $savedAptMark; \
ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \
| awk '/=>/ { print $3 }' \
| sort -u \
| xargs -r dpkg-query -S \
| cut -d: -f1 \
| sort -u \
| xargs -rt apt-mark manual; \
\
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
rm -rf /var/lib/apt/lists/*

# set recommended PHP.ini settings
# see https://docs.nextcloud.com/server/stable/admin_manual/configuration_server/server_tuning.html#enable-php-opcache
RUN { \
echo 'opcache.enable=1'; \
echo 'opcache.interned_strings_buffer=8'; \
echo 'opcache.max_accelerated_files=10000'; \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.save_comments=1'; \
echo 'opcache.revalidate_freq=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini; \
\
echo 'apc.enable_cli=1' >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini; \
\
{ \
echo 'memory_limit=${PHP_MEMORY_LIMIT}'; \
echo 'upload_max_filesize=${PHP_UPLOAD_LIMIT}'; \
echo 'post_max_size=${PHP_UPLOAD_LIMIT}'; \
} > /usr/local/etc/php/conf.d/nextcloud.ini; \
\
mkdir /var/www/data; \
chown -R www-data:root /var/www; \
chmod -R g=u /var/www

VOLUME /var/www/html

RUN a2enmod headers rewrite remoteip ;\
{\
echo RemoteIPHeader X-Real-IP ;\
echo RemoteIPTrustedProxy 10.0.0.0/8 ;\
echo RemoteIPTrustedProxy 172.16.0.0/12 ;\
echo RemoteIPTrustedProxy 192.168.0.0/16 ;\
} > /etc/apache2/conf-available/remoteip.conf;\
a2enconf remoteip

RUN curl -fsSL https://deb.nodesource.com/setup_14.x | bash -
RUN apt-get update && apt-get install -y wget gettext libxml2-utils nodejs && rm -rf /var/lib/apt/lists/*
Expand Down
4 changes: 2 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Changing the property in the tab will also change the DAV property and hence it will be possible to access the
properties via DAV call `PROPFIND`.
]]></description>
<version>2.0.1</version>
<version>2.0.2</version>
<licence>apache</licence>
<author mail="nextcloud@stekoe.de">SteKoe</author>
<namespace>CustomProperties</namespace>
Expand All @@ -27,7 +27,7 @@
https://raw.githubusercontent.com/SteKoe/nextcloud-customproperties/main/.readme/sidebartab.png
</screenshot>
<dependencies>
<php min-version="7.0" />
<php min-version="7.3" />
<nextcloud min-version="20" max-version="22" />
</dependencies>
<settings>
Expand Down
6 changes: 6 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public function __construct(array $urlParams = [])
parent::__construct(self::APP_ID, $urlParams);
}

/**
* @param IRegistrationContext $context
*/
public function register(IRegistrationContext $context): void
{
$context->registerEventListener(
Expand All @@ -38,6 +41,9 @@ public function register(IRegistrationContext $context): void
$context->registerSearchProvider(SearchProvider::class);
}

/**
* @param IBootContext $context
*/
public function boot(IBootContext $context): void
{
// NOOP
Expand Down
7 changes: 7 additions & 0 deletions lib/Controller/CustomPropertiesController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace OCA\CustomProperties\Controller;

Expand All @@ -18,6 +19,12 @@ class CustomPropertiesController extends Controller
*/
private $customPropertiesMapper;

/**
* CustomPropertiesController constructor.
* @param $AppName
* @param IRequest $request
* @param CustomPropertiesMapper $customPropertiesMapper
*/
public function __construct($AppName, IRequest $request, CustomPropertiesMapper $customPropertiesMapper)
{
parent::__construct($AppName, $request);
Expand Down
9 changes: 6 additions & 3 deletions lib/Db/CustomProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ class CustomProperty extends Entity
/** @var string */
public $propertytype;

public String $prefix = Application::NAMESPACE_PREFIX;
public String $namespaceURL = Application::NAMESPACE_URL;
/**
* @var string
*/
public $prefix = Application::NAMESPACE_PREFIX;

public function __construct()
{
Expand All @@ -28,7 +30,8 @@ public function __construct()
$this->addType('propertytype', 'string');
}

public static function withNamespaceURI($propertyname): string {
public static function withNamespaceURI($propertyname): string
{
return "{" . Application::NAMESPACE_URL . "}" . $propertyname;
}

Expand Down
13 changes: 7 additions & 6 deletions lib/Listener/SabreAddPluginListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\SabrePluginEvent;
use Psr\Log\LoggerInterface;

class SabreAddPluginListener implements IEventListener
{
/**
* @var PropertyService
*/
private $propertyService;
private LoggerInterface $logger;

public function __construct(PropertyService $propertyService, LoggerInterface $logger)
/**
* SabreAddPluginListener constructor.
*
* @param PropertyService $propertyService
*/
public function __construct(PropertyService $propertyService)
{
$this->propertyService = $propertyService;
$this->logger = $logger;
}

public function handle(Event $event): void
Expand All @@ -29,8 +31,7 @@ public function handle(Event $event): void
$server = $event->getServer();
$server->addPlugin(new CustomPropertiesSabreServerPlugin(
$this->propertyService,
\OC_User::getUser(),
$this->logger
\OC_User::getUser()
));
}
}
Expand Down
17 changes: 11 additions & 6 deletions lib/Plugin/CustomPropertiesSabreServerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use OCA\CustomProperties\Db\CustomProperty;
use OCA\CustomProperties\Service\PropertyService;
use OCA\DAV\Connector\Sabre\Node;
use Psr\Log\LoggerInterface;
use Sabre\DAV\INode;
use Sabre\DAV\PropFind;
use Sabre\DAV\PropPatch;
Expand All @@ -30,18 +29,24 @@ class CustomPropertiesSabreServerPlugin extends ServerPlugin
/**
* @var CustomProperty[]
*/
private array $customPropertyDefinitions;
private LoggerInterface $logger;
private $customPropertyDefinitions;

public function __construct(PropertyService $propertyService, $userId, LoggerInterface $logger)
/**
* CustomPropertiesSabreServerPlugin constructor.
* @param PropertyService $propertyService
* @param $userId
*/
public function __construct(PropertyService $propertyService, $userId)
{
$this->logger = $logger;
$this->propertyService = $propertyService;
$this->userId = $userId;

$this->customPropertyDefinitions = $this->propertyService->findCustomPropertyDefinitions();
}

/**
* @param Server $server
*/
public function initialize(Server $server)
{
$this->server = $server;
Expand All @@ -50,7 +55,7 @@ public function initialize(Server $server)
$this->server->on('propPatch', [$this, 'propPatch']);
}

private function getCustomPropertynames()
private function getCustomPropertynames(): array
{
return array_map(function (CustomProperty $customProperty) {
return "{" . Application::NAMESPACE_URL . "}" . $customProperty->propertyname;
Expand Down
10 changes: 8 additions & 2 deletions lib/Plugin/CustomPropertySearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@

class CustomPropertySearchResult
{
public Node $node;
public Property $property;
/**
* @var Node
*/
public $node;
/**
* @var Property
*/
public $property;

public function __construct(Node $node, Property $property)
{
Expand Down
34 changes: 29 additions & 5 deletions lib/Plugin/SearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,36 @@

class SearchProvider implements IProvider
{
private IL10N $l10n;
private IURLGenerator $urlGenerator;
private IRootFolder $rootFolder;
private IMimeTypeDetector $mimeTypeDetector;
private PropertiesMapper $propertiesMapper;
/**
* @var IL10N
*/
private $l10n;
/**
* @var IURLGenerator
*/
private $urlGenerator;
/**
* @var IRootFolder
*/
private $rootFolder;
/**
* @var IMimeTypeDetector
*/
private $mimeTypeDetector;
/**
* @var PropertiesMapper
*/
private $propertiesMapper;

/**
* SearchProvider constructor.
*
* @param IL10N $l10n
* @param IURLGenerator $urlGenerator
* @param IMimeTypeDetector $mimeTypeDetector
* @param IRootFolder $rootFolder
* @param PropertiesMapper $propertiesMapper
*/
public function __construct(IL10N $l10n,
IURLGenerator $urlGenerator,
IMimeTypeDetector $mimeTypeDetector,
Expand Down
5 changes: 1 addition & 4 deletions lib/Service/PropertyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ class PropertyService
* @var PropertiesMapper
*/
private $propertiesMapper;
private Server $server;

public function __construct(
CustomPropertiesMapper $customPropertiesMapper,
PropertiesMapper $propertiesMapper,
Server $server
PropertiesMapper $propertiesMapper
)
{
$this->customPropertiesMapper = $customPropertiesMapper;
$this->propertiesMapper = $propertiesMapper;
$this->server = $server;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion tests/Controller/CustomPropertiesControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@

class CustomPropertiesControllerTest extends TestCase
{
private CustomPropertiesController $controller;
/**
* @var CustomPropertiesController
*/
private $controller;
/**
* @var CustomPropertiesMapper|\PHPUnit\Framework\MockObject\MockObject
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/Plugin/SabreServerPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SabreServerPluginTest extends TestCase
/**
* @var PropertyService
*/
private PropertyService $propertyService;
private $propertyService;

protected function setUp(): void
{
Expand Down

0 comments on commit da96734

Please sign in to comment.