To make sure that there is no concurrent operation on the datastore file.
Fixes #1132
<?php
namespace Shaarli\Api;
+use malkusch\lock\mutex\FlockMutex;
use Shaarli\Api\Exceptions\ApiAuthorizationException;
use Shaarli\Api\Exceptions\ApiException;
use Shaarli\Bookmark\BookmarkFileService;
$linkDb = new BookmarkFileService(
$conf,
$this->container->get('history'),
+ new FlockMutex(fopen(SHAARLI_MUTEX_FILE, 'r'), 2),
true
);
$this->container['db'] = $linkDb;
use Exception;
+use malkusch\lock\mutex\Mutex;
use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
use Shaarli\Bookmark\Exception\DatastoreNotInitializedException;
use Shaarli\Bookmark\Exception\EmptyDataStoreException;
/** @var bool true for logged in users. Default value to retrieve private bookmarks. */
protected $isLoggedIn;
+ /** @var Mutex */
+ protected $mutex;
+
/**
* @inheritDoc
*/
- public function __construct(ConfigManager $conf, History $history, $isLoggedIn)
+ public function __construct(ConfigManager $conf, History $history, Mutex $mutex, $isLoggedIn)
{
$this->conf = $conf;
$this->history = $history;
+ $this->mutex = $mutex;
$this->pageCacheManager = new PageCacheManager($this->conf->get('resource.page_cache'), $isLoggedIn);
- $this->bookmarksIO = new BookmarkIO($this->conf);
+ $this->bookmarksIO = new BookmarkIO($this->conf, $this->mutex);
$this->isLoggedIn = $isLoggedIn;
if (!$this->isLoggedIn && $this->conf->get('privacy.hide_public_links', false)) {
namespace Shaarli\Bookmark;
+use malkusch\lock\mutex\Mutex;
+use malkusch\lock\mutex\NoMutex;
use Shaarli\Bookmark\Exception\DatastoreNotInitializedException;
use Shaarli\Bookmark\Exception\EmptyDataStoreException;
use Shaarli\Bookmark\Exception\NotWritableDataStoreException;
*/
protected $conf;
+
+ /** @var Mutex */
+ protected $mutex;
+
/**
* string Datastore PHP prefix
*/
protected static $phpPrefix = '<?php /* ';
-
/**
* string Datastore PHP suffix
*/
*
* @param ConfigManager $conf instance
*/
- public function __construct($conf)
+ public function __construct(ConfigManager $conf, Mutex $mutex = null)
{
+ if ($mutex === null) {
+ // This should only happen with legacy classes
+ $mutex = new NoMutex();
+ }
$this->conf = $conf;
$this->datastore = $conf->get('resource.datastore');
+ $this->mutex = $mutex;
}
/**
throw new NotWritableDataStoreException($this->datastore);
}
+ $content = null;
+ $this->mutex->synchronized(function () use (&$content) {
+ $content = file_get_contents($this->datastore);
+ });
+
// Note that gzinflate is faster than gzuncompress.
// See: http://www.php.net/manual/en/function.gzdeflate.php#96439
$links = unserialize(gzinflate(base64_decode(
- substr(file_get_contents($this->datastore),
- strlen(self::$phpPrefix), -strlen(self::$phpSuffix)))));
+ substr($content, strlen(self::$phpPrefix), -strlen(self::$phpSuffix))
+ )));
if (empty($links)) {
if (filesize($this->datastore) > 100) {
throw new NotWritableDataStoreException(dirname($this->datastore));
}
- file_put_contents(
- $this->datastore,
- self::$phpPrefix.base64_encode(gzdeflate(serialize($links))).self::$phpSuffix
- );
+ $data = self::$phpPrefix.base64_encode(gzdeflate(serialize($links))).self::$phpSuffix;
+
+ $this->mutex->synchronized(function () use ($data) {
+ file_put_contents(
+ $this->datastore,
+ $data
+ );
+ });
}
}
use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
use Shaarli\Bookmark\Exception\NotWritableDataStoreException;
-use Shaarli\Config\ConfigManager;
-use Shaarli\History;
/**
* Class BookmarksService
*/
interface BookmarkServiceInterface
{
- /**
- * BookmarksService constructor.
- *
- * @param ConfigManager $conf instance
- * @param History $history instance
- * @param bool $isLoggedIn true if the current user is logged in
- */
- public function __construct(ConfigManager $conf, History $history, $isLoggedIn);
-
/**
* Find a bookmark by hash
*
namespace Shaarli\Container;
+use malkusch\lock\mutex\FlockMutex;
use Shaarli\Bookmark\BookmarkFileService;
use Shaarli\Bookmark\BookmarkServiceInterface;
use Shaarli\Config\ConfigManager;
return new BookmarkFileService(
$container->conf,
$container->history,
+ new FlockMutex(fopen(SHAARLI_MUTEX_FILE, 'r'), 2),
$container->loginManager->isLoggedIn()
);
};
"erusev/parsedown": "^1.6",
"erusev/parsedown-extra": "^0.8.1",
"gettext/gettext": "^4.4",
+ "malkusch/lock": "^2.1",
"pubsubhubbub/publisher": "dev-master",
"shaarli/netscape-bookmark-parser": "^2.1",
"slim/slim": "^3.0"
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "f84918821b0dceb0cd569875c0418bb8",
+ "content-hash": "932b191006135ff8be495aa0b4ba7e09",
"packages": [
{
"name": "arthurhoaro/web-thumbnailer",
},
"time": "2016-11-07T19:29:14+00:00"
},
+ {
+ "name": "malkusch/lock",
+ "version": "v2.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/php-lock/lock.git",
+ "reference": "093f389ec2f38fc8686d2f70e23378182fce7714"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/php-lock/lock/zipball/093f389ec2f38fc8686d2f70e23378182fce7714",
+ "reference": "093f389ec2f38fc8686d2f70e23378182fce7714",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=7.1",
+ "psr/log": "^1"
+ },
+ "require-dev": {
+ "eloquent/liberator": "^2.0",
+ "ext-memcached": "*",
+ "ext-pcntl": "*",
+ "ext-pdo_mysql": "*",
+ "ext-pdo_sqlite": "*",
+ "ext-redis": "*",
+ "ext-sysvsem": "*",
+ "johnkary/phpunit-speedtrap": "^3.0",
+ "kriswallsmith/spork": "^0.3",
+ "mikey179/vfsstream": "^1.6",
+ "php-mock/php-mock-phpunit": "^2.1",
+ "phpunit/phpunit": "^7.4",
+ "predis/predis": "^1.1",
+ "squizlabs/php_codesniffer": "^3.3"
+ },
+ "suggest": {
+ "ext-pnctl": "Enables locking with flock without busy waiting in CLI scripts.",
+ "ext-redis": "To use this library with the PHP Redis extension.",
+ "ext-sysvsem": "Enables locking using semaphores.",
+ "predis/predis": "To use this library with predis."
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "malkusch\\lock\\": "classes/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "WTFPL"
+ ],
+ "authors": [
+ {
+ "name": "Markus Malkusch",
+ "email": "markus@malkusch.de",
+ "homepage": "http://markus.malkusch.de",
+ "role": "Developer"
+ },
+ {
+ "name": "Willem Stuursma-Ruwen",
+ "email": "willem@stuursma.name",
+ "role": "Developer"
+ }
+ ],
+ "description": "Mutex library for exclusive code execution.",
+ "homepage": "https://github.com/malkusch/lock",
+ "keywords": [
+ "advisory-locks",
+ "cas",
+ "flock",
+ "lock",
+ "locking",
+ "memcache",
+ "mutex",
+ "mysql",
+ "postgresql",
+ "redis",
+ "redlock",
+ "semaphore"
+ ],
+ "support": {
+ "issues": "https://github.com/php-lock/lock/issues",
+ "source": "https://github.com/php-lock/lock/tree/v2.1"
+ },
+ "time": "2018-12-12T19:53:29+00:00"
+ },
{
"name": "nikic/fast-route",
"version": "v1.3.0",
ini_set('session.use_trans_sid', false);
define('SHAARLI_VERSION', ApplicationUtils::getVersion(__DIR__ .'/'. ApplicationUtils::$VERSION_FILE));
+define('SHAARLI_MUTEX_FILE', __FILE__);
session_name('shaarli');
// Start session if needed (Some server auto-start sessions).
<?php
namespace Shaarli\Api\Controllers;
+use malkusch\lock\mutex\NoMutex;
use Shaarli\Bookmark\BookmarkFileService;
use Shaarli\Config\ConfigManager;
use Shaarli\History;
*/
protected function setUp(): void
{
+ $mutex = new NoMutex();
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('resource.datastore', self::$testDatastore);
$this->refDB = new \ReferenceLinkDB();
$this->container = new Container();
$this->container['conf'] = $this->conf;
- $this->container['db'] = new BookmarkFileService($this->conf, $history, true);
+ $this->container['db'] = new BookmarkFileService($this->conf, $history, $mutex, true);
$this->container['history'] = null;
$this->controller = new Info($this->container);
namespace Shaarli\Api\Controllers;
+use malkusch\lock\mutex\NoMutex;
use Shaarli\Bookmark\BookmarkFileService;
use Shaarli\Config\ConfigManager;
use Shaarli\History;
*/
protected $controller;
+ /** @var NoMutex */
+ protected $mutex;
+
/**
* Before each test, instantiate a new Api with its config, plugins and bookmarks.
*/
protected function setUp(): void
{
+ $this->mutex = new NoMutex();
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('resource.datastore', self::$testDatastore);
$this->refDB = new \ReferenceLinkDB();
$refHistory = new \ReferenceHistory();
$refHistory->write(self::$testHistory);
$this->history = new History(self::$testHistory);
- $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true);
+ $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$this->container = new Container();
$this->container['conf'] = $this->conf;
$this->assertEquals(204, $response->getStatusCode());
$this->assertEmpty((string) $response->getBody());
- $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true);
+ $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$this->assertFalse($this->bookmarkService->exists($id));
$historyEntry = $this->history->getHistory()[0];
namespace Shaarli\Api\Controllers;
+use malkusch\lock\mutex\NoMutex;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Bookmark\BookmarkFileService;
use Shaarli\Config\ConfigManager;
*/
protected function setUp(): void
{
+ $mutex = new NoMutex();
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('resource.datastore', self::$testDatastore);
$this->refDB = new \ReferenceLinkDB();
$this->container = new Container();
$this->container['conf'] = $this->conf;
- $this->container['db'] = new BookmarkFileService($this->conf, $history, true);
+ $this->container['db'] = new BookmarkFileService($this->conf, $history, $mutex, true);
$this->container['history'] = null;
$this->controller = new Links($this->container);
<?php
namespace Shaarli\Api\Controllers;
+use malkusch\lock\mutex\NoMutex;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Bookmark\BookmarkFileService;
use Shaarli\Bookmark\LinkDB;
*/
protected function setUp(): void
{
+ $mutex = new NoMutex();
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('resource.datastore', self::$testDatastore);
$this->refDB = new \ReferenceLinkDB();
$this->container = new Container();
$this->container['conf'] = $this->conf;
- $this->container['db'] = new BookmarkFileService($this->conf, $history, true);
+ $this->container['db'] = new BookmarkFileService($this->conf, $history, $mutex, true);
$this->container['history'] = null;
$this->controller = new Links($this->container);
namespace Shaarli\Api\Controllers;
+use malkusch\lock\mutex\NoMutex;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Bookmark\BookmarkFileService;
use Shaarli\Config\ConfigManager;
*/
protected function setUp(): void
{
+ $mutex = new NoMutex();
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('resource.datastore', self::$testDatastore);
$this->refDB = new \ReferenceLinkDB();
$refHistory = new \ReferenceHistory();
$refHistory->write(self::$testHistory);
$this->history = new History(self::$testHistory);
- $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true);
+ $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $mutex, true);
$this->container = new Container();
$this->container['conf'] = $this->conf;
namespace Shaarli\Api\Controllers;
+use malkusch\lock\mutex\NoMutex;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Bookmark\BookmarkFileService;
use Shaarli\Config\ConfigManager;
*/
protected function setUp(): void
{
+ $mutex = new NoMutex();
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('resource.datastore', self::$testDatastore);
$this->refDB = new \ReferenceLinkDB();
$refHistory = new \ReferenceHistory();
$refHistory->write(self::$testHistory);
$this->history = new History(self::$testHistory);
- $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true);
+ $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $mutex, true);
$this->container = new Container();
$this->container['conf'] = $this->conf;
namespace Shaarli\Api\Controllers;
+use malkusch\lock\mutex\NoMutex;
use Shaarli\Bookmark\BookmarkFileService;
use Shaarli\Bookmark\LinkDB;
use Shaarli\Config\ConfigManager;
*/
protected $controller;
+ /** @var NoMutex */
+ protected $mutex;
+
/**
* Before each test, instantiate a new Api with its config, plugins and bookmarks.
*/
protected function setUp(): void
{
+ $this->mutex = new NoMutex();
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('resource.datastore', self::$testDatastore);
$this->refDB = new \ReferenceLinkDB();
$refHistory = new \ReferenceHistory();
$refHistory->write(self::$testHistory);
$this->history = new History(self::$testHistory);
- $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true);
+ $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$this->container = new Container();
$this->container['conf'] = $this->conf;
$this->assertEquals(204, $response->getStatusCode());
$this->assertEmpty((string) $response->getBody());
- $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true);
+ $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$tags = $this->bookmarkService->bookmarksCountPerTag();
$this->assertFalse(isset($tags[$tagName]));
$this->assertEquals(204, $response->getStatusCode());
$this->assertEmpty((string) $response->getBody());
- $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true);
+ $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$tags = $this->bookmarkService->bookmarksCountPerTag();
$this->assertFalse(isset($tags[$tagName]));
$this->assertTrue($tags[strtolower($tagName)] > 0);
namespace Shaarli\Api\Controllers;
+use malkusch\lock\mutex\NoMutex;
use Shaarli\Bookmark\BookmarkFileService;
use Shaarli\Bookmark\LinkDB;
use Shaarli\Config\ConfigManager;
*/
protected function setUp(): void
{
+ $mutex = new NoMutex();
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('resource.datastore', self::$testDatastore);
$this->refDB = new \ReferenceLinkDB();
$this->container = new Container();
$this->container['conf'] = $this->conf;
- $this->container['db'] = new BookmarkFileService($this->conf, $history, true);
+ $this->container['db'] = new BookmarkFileService($this->conf, $history, $mutex, true);
$this->container['history'] = null;
$this->controller = new Tags($this->container);
<?php
namespace Shaarli\Api\Controllers;
+use malkusch\lock\mutex\NoMutex;
use Shaarli\Bookmark\BookmarkFileService;
use Shaarli\Bookmark\LinkDB;
use Shaarli\Config\ConfigManager;
*/
protected function setUp(): void
{
+ $mutex = new NoMutex();
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('resource.datastore', self::$testDatastore);
$this->refDB = new \ReferenceLinkDB();
$this->refDB->write(self::$testDatastore);
$history = new History('sandbox/history.php');
- $this->bookmarkService = new BookmarkFileService($this->conf, $history, true);
+ $this->bookmarkService = new BookmarkFileService($this->conf, $history, $mutex, true);
$this->container = new Container();
$this->container['conf'] = $this->conf;
namespace Shaarli\Api\Controllers;
+use malkusch\lock\mutex\NoMutex;
use Shaarli\Api\Exceptions\ApiBadParametersException;
use Shaarli\Bookmark\BookmarkFileService;
use Shaarli\Bookmark\LinkDB;
*/
protected function setUp(): void
{
+ $mutex = new NoMutex();
$this->conf = new ConfigManager('tests/utils/config/configJson');
$this->conf->set('resource.datastore', self::$testDatastore);
$this->refDB = new \ReferenceLinkDB();
$refHistory = new \ReferenceHistory();
$refHistory->write(self::$testHistory);
$this->history = new History(self::$testHistory);
- $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true);
+ $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $mutex, true);
$this->container = new Container();
$this->container['conf'] = $this->conf;
namespace Shaarli\Bookmark;
use DateTime;
+use malkusch\lock\mutex\NoMutex;
use ReferenceLinkDB;
use ReflectionClass;
use Shaarli;
*/
protected $privateLinkDB = null;
+ /** @var NoMutex */
+ protected $mutex;
+
/**
* Instantiates public and private LinkDBs with test data
*
*/
protected function setUp(): void
{
+ $this->mutex = new NoMutex();
+
if (file_exists(self::$testDatastore)) {
unlink(self::$testDatastore);
}
$this->refDB = new \ReferenceLinkDB();
$this->refDB->write(self::$testDatastore);
$this->history = new History('sandbox/history.php');
- $this->publicLinkDB = new BookmarkFileService($this->conf, $this->history, false);
- $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, true);
+ $this->publicLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, false);
+ $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
}
/**
$db = self::getMethod('migrate');
$db->invokeArgs($this->privateLinkDB, []);
- $db = new \FakeBookmarkService($this->conf, $this->history, true);
+ $db = new \FakeBookmarkService($this->conf, $this->history, $this->mutex, true);
$this->assertInstanceOf(BookmarkArray::class, $db->getBookmarks());
$this->assertEquals($this->refDB->countLinks(), $db->count());
}
$this->assertEquals($updated, $bookmark->getUpdated());
// reload from file
- $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, true);
+ $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$bookmark = $this->privateLinkDB->get(43);
$this->assertEquals(43, $bookmark->getId());
$this->assertNull($bookmark->getUpdated());
// reload from file
- $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, true);
+ $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$bookmark = $this->privateLinkDB->get(43);
$this->assertEquals(43, $bookmark->getId());
$this->assertEquals(43, $bookmark->getId());
// reload from file
- $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, true);
+ $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$this->privateLinkDB->get(43);
}
$this->assertTrue(new \DateTime('5 seconds ago') < $bookmark->getUpdated());
// reload from file
- $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, true);
+ $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$bookmark = $this->privateLinkDB->get(42);
$this->assertEquals(42, $bookmark->getId());
$this->assertTrue(new \DateTime('5 seconds ago') < $bookmark->getUpdated());
// reload from file
- $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, true);
+ $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$bookmark = $this->privateLinkDB->get(42);
$this->assertEquals(42, $bookmark->getId());
$this->assertEquals($title, $bookmark->getTitle());
// reload from file
- $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, true);
+ $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$bookmark = $this->privateLinkDB->get(42);
$this->assertEquals(42, $bookmark->getId());
$this->assertEquals(43, $bookmark->getId());
// reload from file
- $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, true);
+ $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$bookmark = $this->privateLinkDB->get(43);
$this->assertEquals(43, $bookmark->getId());
$this->assertEquals($title, $bookmark->getTitle());
// reload from file
- $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, true);
+ $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$bookmark = $this->privateLinkDB->get(42);
$this->assertEquals(42, $bookmark->getId());
$this->assertEquals($title, $bookmark->getTitle());
// reload from file
- $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, true);
+ $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$bookmark = $this->privateLinkDB->get(42);
$this->assertEquals(42, $bookmark->getId());
$this->assertInstanceOf(BookmarkNotFoundException::class, $exception);
// reload from file
- $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, true);
+ $this->privateLinkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$this->privateLinkDB->get(42);
}
$conf = new ConfigManager('tests/utils/config/configJson');
$conf->set('resource.datastore', 'null/store.db');
- new BookmarkFileService($conf, $this->history, true);
+ new BookmarkFileService($conf, $this->history, $this->mutex, true);
}
/**
{
unlink(self::$testDatastore);
$this->assertFileNotExists(self::$testDatastore);
- new BookmarkFileService($this->conf, $this->history, true);
+ new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$this->assertFileExists(self::$testDatastore);
// ensure the correct data has been written
{
unlink(self::$testDatastore);
$this->assertFileNotExists(self::$testDatastore);
- $db = new \FakeBookmarkService($this->conf, $this->history, false);
+ $db = new \FakeBookmarkService($this->conf, $this->history, $this->mutex, false);
$this->assertFileNotExists(self::$testDatastore);
$this->assertInstanceOf(BookmarkArray::class, $db->getBookmarks());
$this->assertCount(0, $db->getBookmarks());
*/
public function testSave()
{
- $testDB = new BookmarkFileService($this->conf, $this->history, true);
+ $testDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$dbSize = $testDB->count();
$bookmark = new Bookmark();
$testDB->add($bookmark);
- $testDB = new BookmarkFileService($this->conf, $this->history, true);
+ $testDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$this->assertEquals($dbSize + 1, $testDB->count());
}
public function testCountHiddenPublic()
{
$this->conf->set('privacy.hide_public_links', true);
- $linkDB = new BookmarkFileService($this->conf, $this->history, false);
+ $linkDB = new BookmarkFileService($this->conf, $this->history, $this->mutex, false);
$this->assertEquals(0, $linkDB->count());
}
namespace Shaarli\Bookmark;
use Exception;
+use malkusch\lock\mutex\NoMutex;
use ReferenceLinkDB;
use Shaarli\Config\ConfigManager;
use Shaarli\History;
*/
public static function setUpBeforeClass(): void
{
+ $mutex = new NoMutex();
$conf = new ConfigManager('tests/utils/config/configJson');
$conf->set('resource.datastore', self::$testDatastore);
self::$refDB = new \ReferenceLinkDB();
self::$refDB->write(self::$testDatastore);
$history = new History('sandbox/history.php');
- self::$bookmarkService = new \FakeBookmarkService($conf, $history, true);
+ self::$bookmarkService = new \FakeBookmarkService($conf, $history, $mutex, true);
self::$linkFilter = new BookmarkFilter(self::$bookmarkService->getBookmarks());
}
namespace Shaarli\Bookmark;
+use malkusch\lock\mutex\NoMutex;
use Shaarli\Config\ConfigManager;
use Shaarli\History;
use Shaarli\TestCase;
/** @var BookmarkInitializer instance */
protected $initializer;
+ /** @var NoMutex */
+ protected $mutex;
+
/**
* Initialize an empty BookmarkFileService
*/
public function setUp(): void
{
+ $this->mutex = new NoMutex();
if (file_exists(self::$testDatastore)) {
unlink(self::$testDatastore);
}
$this->conf = new ConfigManager(self::$testConf);
$this->conf->set('resource.datastore', self::$testDatastore);
$this->history = new History('sandbox/history.php');
- $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true);
+ $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$this->initializer = new BookmarkInitializer($this->bookmarkService);
}
{
$refDB = new \ReferenceLinkDB();
$refDB->write(self::$testDatastore);
- $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true);
+ $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$this->initializer = new BookmarkInitializer($this->bookmarkService);
$this->initializer->initialize();
$this->bookmarkService->save();
// Reload from file
- $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true);
+ $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$this->assertEquals($refDB->countLinks() + 3, $this->bookmarkService->count());
$bookmark = $this->bookmarkService->get(43);
public function testInitializeNonExistentDataStore(): void
{
$this->conf->set('resource.datastore', static::$testDatastore . '_empty');
- $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true);
+ $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true);
$this->initializer->initialize();
require_once 'tests/utils/ReferenceSessionIdHashes.php';
\ReferenceSessionIdHashes::genAllHashes();
+
+if (!defined('SHAARLI_MUTEX_FILE')) {
+ define('SHAARLI_MUTEX_FILE', __FILE__);
+}
namespace Shaarli\Feed;
use DateTime;
+use malkusch\lock\mutex\NoMutex;
use ReferenceLinkDB;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Bookmark\BookmarkFileService;
*/
public static function setUpBeforeClass(): void
{
+ $mutex = new NoMutex();
$conf = new ConfigManager('tests/utils/config/configJson');
$conf->set('resource.datastore', self::$testDatastore);
$refLinkDB = new \ReferenceLinkDB();
$history = new History('sandbox/history.php');
$factory = new FormatterFactory($conf, true);
self::$formatter = $factory->getFormatter();
- self::$bookmarkService = new BookmarkFileService($conf, $history, true);
+ self::$bookmarkService = new BookmarkFileService($conf, $history, $mutex, true);
self::$serverInfo = array(
'HTTPS' => 'Off',
namespace Shaarli\Netscape;
+use malkusch\lock\mutex\NoMutex;
use Shaarli\Bookmark\BookmarkFileService;
use Shaarli\Config\ConfigManager;
use Shaarli\Formatter\BookmarkFormatter;
*/
public static function setUpBeforeClass(): void
{
+ $mutex = new NoMutex();
static::$conf = new ConfigManager('tests/utils/config/configJson');
static::$conf->set('resource.datastore', static::$testDatastore);
static::$refDb = new \ReferenceLinkDB();
static::$refDb->write(static::$testDatastore);
static::$history = new History('sandbox/history.php');
- static::$bookmarkService = new BookmarkFileService(static::$conf, static::$history, true);
+ static::$bookmarkService = new BookmarkFileService(static::$conf, static::$history, $mutex, true);
$factory = new FormatterFactory(static::$conf, true);
static::$formatter = $factory->getFormatter('raw');
}
namespace Shaarli\Netscape;
use DateTime;
+use malkusch\lock\mutex\NoMutex;
use Psr\Http\Message\UploadedFileInterface;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Bookmark\BookmarkFileService;
*/
protected function setUp(): void
{
+ $mutex = new NoMutex();
if (file_exists(self::$testDatastore)) {
unlink(self::$testDatastore);
}
$this->conf->set('resource.page_cache', $this->pagecache);
$this->conf->set('resource.datastore', self::$testDatastore);
$this->history = new History(self::$historyFilePath);
- $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true);
+ $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $mutex, true);
$this->netscapeBookmarkUtils = new NetscapeBookmarkUtils($this->bookmarkService, $this->conf, $this->history);
}
namespace Shaarli\Updater;
use Exception;
+use malkusch\lock\mutex\NoMutex;
use Shaarli\Bookmark\BookmarkFileService;
use Shaarli\Bookmark\BookmarkServiceInterface;
use Shaarli\Config\ConfigManager;
*/
protected function setUp(): void
{
+ $mutex = new NoMutex();
$this->refDB = new \ReferenceLinkDB();
$this->refDB->write(self::$testDatastore);
copy('tests/utils/config/configJson.json.php', self::$configFile .'.json.php');
$this->conf = new ConfigManager(self::$configFile);
- $this->bookmarkService = new BookmarkFileService($this->conf, $this->createMock(History::class), true);
+ $this->bookmarkService = new BookmarkFileService($this->conf, $this->createMock(History::class), $mutex, true);
$this->updater = new Updater([], $this->bookmarkService, $this->conf, true);
}