-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bojan Bogdanovic
committed
Sep 7, 2024
1 parent
c06b861
commit baf390c
Showing
17 changed files
with
1,590 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
namespace Drupal\next; | ||
|
||
use Drupal\Core\Database\Connection; | ||
|
||
/** | ||
* Defines the cache tag node mapper service. | ||
*/ | ||
class CacheTagNodeMapper implements CacheTagNodeMapperInterface { | ||
|
||
/** | ||
* Database Service Object. | ||
* | ||
* @var \Drupal\Core\Database\Connection | ||
*/ | ||
private Connection $connection; | ||
|
||
/** | ||
* Construct the CacheTagNodeMapper. | ||
* | ||
* @param \Drupal\Core\Database\Connection $connection | ||
* The database connection. | ||
*/ | ||
public function __construct(Connection $connection) { | ||
$this->connection = $connection; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getCacheTagsByNid(int $nid, string $langcode, string $next_site): array { | ||
return $this->connection->select(self::TABLE, 'c') | ||
->fields('c', ['tag']) | ||
->condition('c.nid', $nid) | ||
->condition('c.langcode', $langcode) | ||
->condition('c.next_site', $next_site) | ||
->execute() | ||
->fetchCol(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getNidsByCacheTag(string $cache_tag, string $langcode, $next_site): array { | ||
return $this->connection->select(self::TABLE, 'c') | ||
->fields('c', ['nid']) | ||
->condition('c.tag', $cache_tag) | ||
->condition('c.langcode', $langcode) | ||
->condition('c.next_site', $next_site) | ||
->distinct() | ||
->execute() | ||
->fetchCol(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function delete(array $cache_tags, string $langcode, ?int $nid = NULL, ?string $next_site = NULL): void { | ||
$query = $this->connection->delete(self::TABLE) | ||
->condition('langcode', $langcode); | ||
|
||
if (count($cache_tags) > 1) { | ||
$query->condition('tag', $cache_tags, 'IN'); | ||
} | ||
else { | ||
$query->condition('tag', reset($cache_tags)); | ||
} | ||
|
||
if ($nid) { | ||
$query->condition('nid', $nid); | ||
} | ||
if ($next_site) { | ||
$query->condition('next_site', $next_site); | ||
} | ||
|
||
$query->execute(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function add(array $values): void { | ||
$query = $this->connection->insert(self::TABLE) | ||
->fields(['tag', 'nid', 'langcode', 'next_site']); | ||
foreach ($values as $row) { | ||
$query->values($row); | ||
} | ||
$query->execute(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace Drupal\next; | ||
|
||
/** | ||
* Cache tag node mapper interface. | ||
*/ | ||
interface CacheTagNodeMapperInterface { | ||
|
||
/** | ||
* The table name. | ||
*/ | ||
const TABLE = 'cachetag_node_map'; | ||
|
||
/** | ||
* Get cache tags by node id. | ||
* | ||
* @param int $nid | ||
* The node id. | ||
* @param string $langcode | ||
* The language code. | ||
* @param string $next_site | ||
* The next site id. | ||
* | ||
* @return array | ||
* Returns array with cache tags. | ||
*/ | ||
public function getCacheTagsByNid(int $nid, string $langcode, string $next_site): array; | ||
|
||
/** | ||
* Get node id's by cache tag. | ||
* | ||
* @param string $cache_tag | ||
* The cache tag. | ||
* @param string $langcode | ||
* The language code. | ||
* @param string $next_site | ||
* The next site id. | ||
* | ||
* @return array | ||
* Returns array with node id's. | ||
*/ | ||
public function getNidsByCacheTag(string $cache_tag, string $langcode, string $next_site): array; | ||
|
||
/** | ||
* Delete cache tags. | ||
* | ||
* @param array $cache_tags | ||
* The cache tags. | ||
* @param string $langcode | ||
* The language code. | ||
* @param int|null $nid | ||
* Optional node id. | ||
* @param string|null $next_site | ||
* Optional next site id. | ||
*/ | ||
public function delete(array $cache_tags, string $langcode, ?int $nid = NULL, ?string $next_site = NULL): void; | ||
|
||
/** | ||
* Add cache tags. | ||
* | ||
* @param array $values | ||
* Cache tags values to add. | ||
* E.g: [ | ||
* [ | ||
* 'tag' => 'node:1', | ||
* 'nid' => '1', | ||
* 'langcode' => 'en', | ||
* 'next_site' => example, | ||
* ] | ||
* ]. | ||
*/ | ||
public function add(array $values): void; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Drupal\next; | ||
|
||
use Drupal\Core\Database\Connection; | ||
|
||
/** | ||
* Defines the cache tag revalidator task store service. | ||
*/ | ||
class CacheTagRevalidatorTaskStore implements CacheTagRevalidatorTaskStoreInterface { | ||
|
||
/** | ||
* Database Service Object. | ||
* | ||
* @var \Drupal\Core\Database\Connection | ||
*/ | ||
private Connection $connection; | ||
|
||
/** | ||
* Construct the CacheTagRevalidatorTaskStore. | ||
* | ||
* @param \Drupal\Core\Database\Connection $connection | ||
* The database connection. | ||
*/ | ||
public function __construct(Connection $connection) { | ||
$this->connection = $connection; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function set(array $nids, string $langcode, string $next_site): void { | ||
$query = $this->connection->insert(self::TABLE) | ||
->fields(['nid', 'langcode', 'next_site']); | ||
foreach ($nids as $nid) { | ||
$query->values([ | ||
'nid' => $nid, | ||
'langcode' => $langcode, | ||
'next_site' => $next_site, | ||
]); | ||
} | ||
$query->execute(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function has(int $nid, string $langcode, string $next_site): bool { | ||
return (bool) $this->connection->select(self::TABLE, 'c') | ||
->fields('c', ['nid']) | ||
->condition('c.nid', $nid) | ||
->condition('c.langcode', $langcode) | ||
->condition('c.next_site', $next_site) | ||
->execute() | ||
->fetchField(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function delete(array $nids, string $langcode, string $next_site): void { | ||
$this->connection->delete(self::TABLE) | ||
->condition('nid', $nids, 'IN') | ||
->condition('langcode', $langcode) | ||
->condition('next_site', $next_site) | ||
->execute(); | ||
} | ||
|
||
} |
Oops, something went wrong.