e posts clauses with "from", "where" * @return {string[]} The posts clauses * @hook RML/Count/PostsClauses */ $sql = \apply_filters('RML/Count/PostsClauses', ['from' => $this->getTableName('posts') . ' AS rmlpostscnt', 'where' => 'rmlpostscnt.fid = tn.id', 'afterWhere' => '']); return 'SELECT COUNT(*) FROM ' . $sql['from'] . ' WHERE ' . $sql['where'] . ' ' . $sql['afterWhere']; } /** * Reset the count cache for the current blog id. The content of the array is not prepared for the statement * * @param int $folderId Array If you pass folder id/ids array, only this one will be reset. * @return CountCache */ public function resetCountCache($folderId = null) { global $wpdb; $table_name = $this->getTableName(); // phpcs:disable WordPress.DB.PreparedSQL if (\is_array($folderId)) { $wpdb->query("UPDATE {$table_name} SET cnt=NULL WHERE id IN (" . \implode(',', $folderId) . ')'); } else { $wpdb->query("UPDATE {$table_name} SET cnt=NULL"); } // phpcs:enable WordPress.DB.PreparedSQL /** * Reset a count cache for a folder or all folders. * * @param {int} $folderId Can be `null` if all folders need to be reset * @hook RML/Count/Reset * @since 4.10.3 */ \do_action('RML/Count/Reset', $folderId); return $this; } /** * Is fired with wp_die event. * * @param int $folderId The folder id */ public function resetCountCacheOnWpDie($folderId) { if (!\in_array($folderId, $this->folderIdsOnWpDie, \true)) { $this->folderIdsOnWpDie[] = $folderId; } } /** * Update at the end of the script execution the count of the given added / deleted attachments. */ public function wp_die() { if (\count($this->newAttachments) > 0) { $this->debug('Update count cache on wp die...', __METHOD__); $this->updateCountCache(null, $this->newAttachments); } if (\count($this->folderIdsOnWpDie) > 0) { $this->debug('Update count cache on wp die...', __METHOD__); $this->updateCountCache($this->folderIdsOnWpDie); } // Reset because this function can be called multiple $this->newAttachments = []; $this->folderIdsOnWpDie = []; } /** * Add an attachment to the update queue. * * @param int $id The attachment id */ public function addNewAttachment($id) { $this->newAttachments[] = $id; return $this; } /** * Get instance. * * @return CountCache */ public static function getInstance() { return self::$me === null ? self::$me = new \MatthiasWeb\RealMediaLibrary\attachment\CountCache() : self::$me; } } e posts clauses with "from", "where" * @return {string[]} The posts clauses * @hook RML/Count/PostsClauses */ $sql = \apply_filters('RML/Count/PostsClauses', ['from' => $this->getTableName('posts') . ' AS rmlpostscnt', 'where' => 'rmlpostscnt.fid = tn.id', 'afterWhere' => '']); return 'SELECT COUNT(*) FROM ' . $sql['from'] . ' WHERE ' . $sql['where'] . ' ' . $sql['afterWhere']; } /** * Reset the count cache for the current blog id. The content of the array is not prepared for the statement * * @param int $folderId Array If you pass folder id/ids array, only this one will be reset. * @return CountCache */ public function resetCountCache($folderId = null) { global $wpdb; $table_name = $this->getTableName(); // phpcs:disable WordPress.DB.PreparedSQL if (\is_array($folderId)) { $wpdb->query("UPDATE {$table_name} SET cnt=NULL WHERE id IN (" . \implode(',', $folderId) . ')'); } else { $wpdb->query("UPDATE {$table_name} SET cnt=NULL"); } // phpcs:enable WordPress.DB.PreparedSQL /** * Reset a count cache for a folder or all folders. * * @param {int} $folderId Can be `null` if all folders need to be reset * @hook RML/Count/Reset * @since 4.10.3 */ \do_action('RML/Count/Reset', $folderId); return $this; } /** * Is fired with wp_die event. * * @param int $folderId The folder id */ public function resetCountCacheOnWpDie($folderId) { if (!\in_array($folderId, $this->folderIdsOnWpDie, \true)) { $this->folderIdsOnWpDie[] = $folderId; } } /** * Update at the end of the script execution the count of the given added / deleted attachments. */ public function wp_die() { if (\count($this->newAttachments) > 0) { $this->debug('Update count cache on wp die...', __METHOD__); $this->updateCountCache(null, $this->newAttachments); } if (\count($this->folderIdsOnWpDie) > 0) { $this->debug('Update count cache on wp die...', __METHOD__); $this->updateCountCache($this->folderIdsOnWpDie); } // Reset because this function can be called multiple $this->newAttachments = []; $this->folderIdsOnWpDie = []; } /** * Add an attachment to the update queue. * * @param int $id The attachment id */ public function addNewAttachment($id) { $this->newAttachments[] = $id; return $this; } /** * Get instance. * * @return CountCache */ public static function getInstance() { return self::$me === null ? self::$me = new \MatthiasWeb\RealMediaLibrary\attachment\CountCache() : self::$me; } }