WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Платформа для конвертации и монетизации трафика
функция не описана

SimplePie_Cache_MySQL::save() public WP 1.0

Save data to the cache

{} Это метод класса: SimplePie_Cache_MySQL{}

Хуков нет.

Возвращает

true/false. Successfulness

Использование

$SimplePie_Cache_MySQL = new SimplePie_Cache_MySQL();
$SimplePie_Cache_MySQL->save( $data );
$data(массив/SimplePie) (обязательный)
Data to store in the cache. If passed a SimplePie object, only cache the $data property

Код SimplePie_Cache_MySQL::save() WP 5.5.3

<?php
public function save($data)
{
	if ($this->mysql === null)
	{
		return false;
	}

	$query = $this->mysql->prepare('DELETE i, cd FROM `' . $this->options['extras']['prefix'] . 'cache_data` cd, ' .
		'`' . $this->options['extras']['prefix'] . 'items` i ' .
		'WHERE cd.id = i.feed_id ' .
		'AND cd.mtime < (unix_timestamp() - :purge_time)');
	$query->bindValue(':purge_time', $this->options['extras']['cache_purge_time']);

	if (!$query->execute())
	{
		return false;
	}

	if ($data instanceof SimplePie)
	{
		$data = clone $data;

		$prepared = self::prepare_simplepie_object_for_cache($data);

		$query = $this->mysql->prepare('SELECT COUNT(*) FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
		$query->bindValue(':feed', $this->id);
		if ($query->execute())
		{
			if ($query->fetchColumn() > 0)
			{
				$items = count($prepared[1]);
				if ($items)
				{
					$sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = :items, `data` = :data, `mtime` = :time WHERE `id` = :feed';
					$query = $this->mysql->prepare($sql);
					$query->bindValue(':items', $items);
				}
				else
				{
					$sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `data` = :data, `mtime` = :time WHERE `id` = :feed';
					$query = $this->mysql->prepare($sql);
				}

				$query->bindValue(':data', $prepared[0]);
				$query->bindValue(':time', time());
				$query->bindValue(':feed', $this->id);
				if (!$query->execute())
				{
					return false;
				}
			}
			else
			{
				$query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:feed, :count, :data, :time)');
				$query->bindValue(':feed', $this->id);
				$query->bindValue(':count', count($prepared[1]));
				$query->bindValue(':data', $prepared[0]);
				$query->bindValue(':time', time());
				if (!$query->execute())
				{
					return false;
				}
			}

			$ids = array_keys($prepared[1]);
			if (!empty($ids))
			{
				foreach ($ids as $id)
				{
					$database_ids[] = $this->mysql->quote($id);
				}

				$query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `id` = ' . implode(' OR `id` = ', $database_ids) . ' AND `feed_id` = :feed');
				$query->bindValue(':feed', $this->id);

				if ($query->execute())
				{
					$existing_ids = array();
					while ($row = $query->fetchColumn())
					{
						$existing_ids[] = $row;
					}

					$new_ids = array_diff($ids, $existing_ids);

					foreach ($new_ids as $new_id)
					{
						if (!($date = $prepared[1][$new_id]->get_date('U')))
						{
							$date = time();
						}

						$query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'items` (`feed_id`, `id`, `data`, `posted`) VALUES(:feed, :id, :data, :date)');
						$query->bindValue(':feed', $this->id);
						$query->bindValue(':id', $new_id);
						$query->bindValue(':data', serialize($prepared[1][$new_id]->data));
						$query->bindValue(':date', $date);
						if (!$query->execute())
						{
							return false;
						}
					}
					return true;
				}
			}
			else
			{
				return true;
			}
		}
	}
	else
	{
		$query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
		$query->bindValue(':feed', $this->id);
		if ($query->execute())
		{
			if ($query->rowCount() > 0)
			{
				$query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = 0, `data` = :data, `mtime` = :time WHERE `id` = :feed');
				$query->bindValue(':data', serialize($data));
				$query->bindValue(':time', time());
				$query->bindValue(':feed', $this->id);
				if ($this->execute())
				{
					return true;
				}
			}
			else
			{
				$query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:id, 0, :data, :time)');
				$query->bindValue(':id', $this->id);
				$query->bindValue(':data', serialize($data));
				$query->bindValue(':time', time());
				if ($query->execute())
				{
					return true;
				}
			}
		}
	}
	return false;
}