Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 39 additions & 0 deletions bin/worker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env php
<?php

/**
* phpMyFAQ background worker.
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*
* @package phpMyFAQ
* @author Thorsten Rinne <thorsten@phpmyfaq.de>
* @copyright 2026 phpMyFAQ Team
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
* @link https://www.phpmyfaq.de
* @since 2026-02-11
*/

declare(strict_types=1);

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;

require __DIR__ . '/../phpmyfaq/src/Bootstrap.php';
require __DIR__ . '/../phpmyfaq/src/autoload.php';

$maxJobs = isset($argv[1]) ? max(0, (int) $argv[1]) : 0;

$container = new ContainerBuilder();
$loader = new PhpFileLoader($container, new FileLocator(__DIR__));
$loader->load('../phpmyfaq/src/services.php');
$container->compile();

$worker = $container->get('phpmyfaq.queue.worker');
$processed = $worker->run($maxJobs);

echo sprintf("Processed %d job(s).\n", $processed);

86 changes: 44 additions & 42 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions phpmyfaq/src/phpMyFAQ/Captcha/GoogleRecaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,18 @@ public function checkCaptchaCode(string $code): bool
$code,
);

$response = file_get_contents($url);
$response = json_decode($response, true, 512, JSON_THROW_ON_ERROR);
return $response['success'] === true;
$response = @file_get_contents($url);
if (!is_string($response) || $response === '') {
return false;
}

try {
$decoded = json_decode($response, true, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException) {
return false;
}

return is_array($decoded) && ($decoded['success'] ?? false) === true;
}

public function isUserIsLoggedIn(): bool
Expand Down
10 changes: 10 additions & 0 deletions phpmyfaq/src/phpMyFAQ/Database/DatabaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ public function getTableNames(string $prefix = ''): array;
*/
public function close();

/**
* Returns the number of rows affected by the last INSERT, UPDATE, or DELETE query.
*/
public function affectedRows(): int;

/**
* Returns the ID of the last inserted row or sequence value.
*/
public function lastInsertId(): int|string;

/**
* Return an SQL expression that yields current datetime in the local timezone.
* The actual SQL value may be of SQL datetime type (or timestamp or similar),
Expand Down
18 changes: 18 additions & 0 deletions phpmyfaq/src/phpMyFAQ/Database/Mysqli.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,16 @@ public function query(string $query, int $offset = 0, int $rowcount = 0): mixed
return $result;
}

/**
* Returns the number of rows affected by the last INSERT, UPDATE, or DELETE query.
*/
public function affectedRows(): int
{
$rows = $this->conn->affected_rows;

return $rows < 0 ? 0 : (int) $rows;
}

/**
* Returns the client version string.
*/
Expand Down Expand Up @@ -350,6 +360,14 @@ public function __destruct()
}
}

/**
* Returns the ID of the last inserted row.
*/
public function lastInsertId(): int|string
{
return (int) $this->conn->insert_id;
}

public function now(): string
{
return 'NOW()';
Expand Down
Loading