From 4a23ffbab88d02c051a480331023f611cd52d6c9 Mon Sep 17 00:00:00 2001 From: Paul <40315177+PAXANDDOS@users.noreply.github.com> Date: Fri, 24 Mar 2023 00:45:11 +0200 Subject: [PATCH] fix: mongodb handler, dockerfile - Fixed MongoDB handler with correct MongoDB classes. This is apparently pretty old handler. Added suggests to the composer.json - In Dockerfile using wget instead of git to get the phpiredis repository; installed mongodb --- Dockerfile | 13 +++--- composer.json | 9 +++-- docker-compose.yml | 40 +++++++++---------- .../Handler/Connector/MongoDBConnector.php | 7 ++-- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/Dockerfile b/Dockerfile index 59a26af..2a77747 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,23 +18,22 @@ RUN apk add --no-cache -t .production-deps \ hiredis libzip RUN set -xe \ - && apk add --no-cache -t .build-deps $PHPIZE_DEPS git \ + && apk add --no-cache -t .build-deps $PHPIZE_DEPS \ hiredis-dev libzip-dev \ - && pecl install -f apcu-5.1.22 redis-5.3.7 \ - && git clone https://github.com/nrk/phpiredis.git \ + && pecl install -f apcu-5.1.22 redis-5.3.7 mongodb-1.15.1 \ + && wget -qO- https://github.com/nrk/phpiredis/archive/v1.1.zip | busybox unzip - \ && ( \ - cd phpiredis \ - && git checkout v1.1 \ + cd phpiredis-1.1 \ && phpize \ && ./configure --enable-phpiredis \ && make \ && make install \ ) \ - && rm -r phpiredis \ + && rm -r phpiredis-1.1 \ && docker-php-source extract \ && docker-php-ext-configure pcntl --enable-pcntl \ && docker-php-ext-install -j$(nproc) pcntl zip \ - && docker-php-ext-enable apcu redis phpiredis \ + && docker-php-ext-enable apcu redis mongodb phpiredis \ && docker-php-source delete \ && pecl clear-cache \ && rm -rf /tmp/* \ diff --git a/composer.json b/composer.json index e58a637..ed1f6bb 100644 --- a/composer.json +++ b/composer.json @@ -29,12 +29,15 @@ "symfony/console": "^5.4|^6.0" }, "suggest": { - "ext-phpiredis": "Native PHP extension for Redis connectivity. Predis will automatically utilize when available.", - "symfony/process": "To run the speed test command.", - "symfony/yaml": "To use the YAML config file." + "ext-mongodb": "For using the MongoDB logger.", + "ext-phpiredis": "For using native Redis connectivity.", + "mongodb/mongodb": "For using the MongoDB logger.", + "symfony/process": "For using the speed test command.", + "symfony/yaml": "For using the YAML configuration file." }, "require-dev": { "phpunit/phpunit": "^9.5", + "mongodb/mongodb": "^1.0", "symfony/process": "^5.4|^6.0", "symfony/yaml": "^5.4|^6.0" }, diff --git a/docker-compose.yml b/docker-compose.yml index 362682f..70ab109 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,26 +1,26 @@ version: "3.9" services: - resque: - container_name: resque - image: resque:latest - restart: unless-stopped - stdin_open: true - tty: true - build: - context: . - args: - - PHP_VERSION=7 - ports: - - 8000:80 - volumes: - - ./:/var/www/resque:rw + resque: + container_name: resque + image: resque:latest + restart: unless-stopped + stdin_open: true + tty: true + build: + context: . + args: + - PHP_VERSION=7 + ports: + - 8000:80 + volumes: + - ./:/var/www/resque:rw - redis: - container_name: resque-redis - image: redis:7.0-alpine - volumes: - - redis:/data:rw + redis: + container_name: resque-redis + image: redis:7.0-alpine + volumes: + - redis:/data:rw volumes: - redis: + redis: diff --git a/src/Logger/Handler/Connector/MongoDBConnector.php b/src/Logger/Handler/Connector/MongoDBConnector.php index b7a9ca2..36bfee0 100644 --- a/src/Logger/Handler/Connector/MongoDBConnector.php +++ b/src/Logger/Handler/Connector/MongoDBConnector.php @@ -11,6 +11,7 @@ namespace Resque\Logger\Handler\Connector; +use MongoDB\Client; use Monolog\Handler\MongoDBHandler; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -30,10 +31,8 @@ public function resolve(Command $command, InputInterface $input, OutputInterface $dsn = strtr('mongodb://host:port', $args); $options = []; - if (class_exists('MongoClient')) { - $mongodb = new \MongoClient($dsn, $options); - } elseif (class_exists('Mongo')) { - $mongodb = new \Mongo($dsn, $options); + if (class_exists(Client::class)) { + $mongodb = new Client($dsn, $options); } return new MongoDBHandler($mongodb, $this->replacePlaceholders($args['dbname']), $this->replacePlaceholders($args['collection']));