forked from laysense/laysense.cn
Manage dynamic blocks and expand the editor library
This commit is contained in:
@@ -86,7 +86,9 @@ final class Repository
|
||||
]);
|
||||
self::checkVersion($query->rowCount());
|
||||
foreach ($sections as $section) {
|
||||
if ($section['version'] === null) {
|
||||
if (!empty($section['delete'])) {
|
||||
self::deleteSection($pdo, $slug, $section['key'], $section['version']);
|
||||
} elseif ($section['version'] === null) {
|
||||
self::insertSection($pdo, $slug, $section['key'], $section);
|
||||
} else {
|
||||
self::updateSection($pdo, $slug, $section['key'], $section, $section['version']);
|
||||
@@ -111,10 +113,10 @@ final class Repository
|
||||
self::checkVersion($query->rowCount());
|
||||
}
|
||||
|
||||
public function createSection(string $page, string $key, string $title, string $style, string $body, ?string $feed = null): void
|
||||
public function createSection(string $page, string $key, string $title, string $style, string $body, ?string $feed = null, string $lead = ''): void
|
||||
{
|
||||
Database::write(function (PDO $pdo) use ($page, $key, $title, $style, $body, $feed): void {
|
||||
self::insertSection($pdo, $page, $key, compact('title', 'style', 'body', 'feed') + ['lead' => '']);
|
||||
Database::write(function (PDO $pdo) use ($page, $key, $title, $style, $body, $feed, $lead): void {
|
||||
self::insertSection($pdo, $page, $key, compact('title', 'style', 'body', 'feed', 'lead'));
|
||||
self::touchPage($pdo, $page, structureChanged: true);
|
||||
});
|
||||
}
|
||||
@@ -129,6 +131,13 @@ final class Repository
|
||||
}
|
||||
}
|
||||
|
||||
private static function deleteSection(PDO $pdo, string $page, string $key, int $version): void
|
||||
{
|
||||
$query = $pdo->prepare('DELETE FROM sections WHERE page_slug = ? AND key = ? AND version = ?');
|
||||
$query->execute([$page, $key, $version]);
|
||||
self::checkVersion($query->rowCount());
|
||||
}
|
||||
|
||||
public function arrangeSection(string $page, string $key, string $operation, int $version, int $pageVersion): void
|
||||
{
|
||||
Database::write(function (PDO $pdo) use ($page, $key, $operation, $version, $pageVersion): void {
|
||||
@@ -137,14 +146,12 @@ final class Repository
|
||||
$revision = $current->fetchColumn();
|
||||
self::checkVersion($revision !== false && (int) $revision === $pageVersion ? 1 : 0);
|
||||
if ($operation === 'delete') {
|
||||
$query = $pdo->prepare('DELETE FROM sections WHERE page_slug = ? AND key = ? AND version = ?');
|
||||
$query->execute([$page, $key, $version]);
|
||||
self::checkVersion($query->rowCount());
|
||||
self::deleteSection($pdo, $page, $key, $version);
|
||||
self::touchPage($pdo, $page, structureChanged: true);
|
||||
|
||||
return;
|
||||
}
|
||||
$query = $pdo->prepare('SELECT key, version FROM sections WHERE page_slug = ? ORDER BY position, key');
|
||||
$query = $pdo->prepare("SELECT key, version FROM sections WHERE page_slug = ? AND style <> 'hero-links' ORDER BY position, key");
|
||||
$query->execute([$page]);
|
||||
$revisions = $query->fetchAll(PDO::FETCH_KEY_PAIR);
|
||||
if (!array_key_exists($key, $revisions)) {
|
||||
|
||||
Reference in New Issue
Block a user