: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
<?php namespace flow\db\migrations;
use la\core\db\LADDLUtils;
use la\core\db\migrations\ILADBMigration;
if ( ! defined( 'WPINC' ) ) die;
* @author Looks Awesome <email@looks-awesome.com>
* @link http://looks-awesome.com
* @copyright Looks Awesome
class FFMigration_2_16 implements ILADBMigration{
public function version() {
public function execute($conn, $manager) {
$this->create_cache_table($conn, $manager->cache_table_name, $manager->posts_table_name, $manager->streams_sources_table_name);
LADDLUtils::addColumnIfNotExist($conn, $manager->cache_table_name, 'settings', 'BLOB');
LADDLUtils::addColumnIfNotExist($conn, $manager->cache_table_name, 'enabled', 'TINYINT(1)');
LADDLUtils::addColumnIfNotExist($conn, $manager->cache_table_name, 'changed_time', 'INT DEFAULT 0');
LADDLUtils::addColumnIfNotExist($conn, $manager->cache_table_name, 'cache_lifetime', 'INT DEFAULT 60');
if (LADDLUtils::existColumn($conn, $manager->cache_table_name, 'stream_id')){
LADDLUtils::dropColumn($conn, $manager->cache_table_name, 'stream_id');
if (LADDLUtils::existColumn($conn, $manager->posts_table_name, 'stream_id')){
LADDLUtils::dropColumn($conn, $manager->posts_table_name, 'stream_id');
$streams = $this->streams($conn, $manager->streams_table_name);
foreach ( $streams as $stream ) {
$stream = $this->getStream($conn, $manager->streams_table_name, $stream['id']);
if (!isset($stream->feeds) || is_null($stream->feeds)){
$feeds = json_decode($stream->feeds);
if (isset($stream->{'cache-lifetime'})){
$cache_lifetime = (int) $stream->{'cache-lifetime'};
if ($cache_lifetime > 5760) $cache_lifetime = 10080;
else if ($cache_lifetime > 900 && $cache_lifetime <= 5760) $cache_lifetime = 1440;
else if ($cache_lifetime > 210 && $cache_lifetime <= 900) $cache_lifetime = 360;
else if ($cache_lifetime > 45 && $cache_lifetime <= 210) $cache_lifetime = 60;
else if ($cache_lifetime > 17 && $cache_lifetime <= 45) $cache_lifetime = 30;
else if (17 >= $cache_lifetime) $cache_lifetime = 5;
if (isset($stream->posts)){
$load_last = (int) $stream->posts;
if ($load_last > 15) $load_last = 20;
else if ($load_last > 8 && $load_last <= 15) $load_last = 10;
else if ($load_last > 3 && $load_last <= 8) $load_last = 5;
else if (3 >= $load_last) $load_last = 1;
foreach ( $feeds as $feed ) {
$feed->posts = $load_last;
if (isset($stream->moderation)){
$feed->mod = $stream->moderation;
'cache_lifetime' => $cache_lifetime
'cache_lifetime' => $cache_lifetime
if ( false === $conn->query( 'INSERT INTO ?n SET `feed_id`=?s, ?u ON DUPLICATE KEY UPDATE ?u',
$manager->cache_table_name, $feed->id, $insert, $update ) ) {
if ( false === $conn->query( 'INSERT INTO ?n SET `feed_id`=?s, `stream_id`=?i',
$manager->streams_sources_table_name, $this->source($f, $feed->id), $stream->id) ) {
if (LADDLUtils::existColumn($conn, $manager->streams_table_name, 'feeds')){
LADDLUtils::dropColumn($conn, $manager->streams_table_name, 'feeds');
private function source($source, $id){
$hash = hash('md5', $source);
if (array_key_exists($hash, $this->sources)){
return $this->sources[$hash];
$this->sources[$hash] = $id;
private function streams($conn, $table_name){
if (false !== ($result = $conn->getAll('SELECT `id`, `value` FROM ?n ORDER BY `id`',
private function getStream($conn, $table_name, $id){
if (false !== ($row = $conn->getRow('select `value`, `feeds` from ?n where `id`=?s', $table_name, $id))) {
$options = unserialize($row['value']);
$options->feeds = $row['feeds'];
private function create_cache_table($conn, $cache_table, $posts_table, $streams2sources_table) {
* We'll set the default character set and collation for this table.
* If we don't do this, some characters could end up being converted
* to just ?'s when saved in our table.
$charset = LADDLUtils::charset();
if ( !empty( $charset ) ) {
$charset_collate = " CHARACTER SET {$charset}";
$charset = " CHARACTER SET {$charset}";
$collate = LADDLUtils::collate();
if ( !empty( $collate ) ) {
$charset_collate .= " COLLATE {$collate}";
if(!LADDLUtils::existTable($conn, $cache_table)){
CREATE TABLE `{$cache_table}`
`feed_id` VARCHAR(20) NOT NULL,
`last_update` INT NOT NULL,
`status` INT NOT NULL DEFAULT 0,
`enabled` TINYINT(1) DEFAULT 0,
`system_enabled` TINYINT(1) DEFAULT 1,
`changed_time` INT DEFAULT 0,
`cache_lifetime` INT DEFAULT 60,
if(!LADDLUtils::existTable($conn, $streams2sources_table)){
CREATE TABLE `{$streams2sources_table}`
`feed_id` VARCHAR(20) NOT NULL,
`stream_id` INT NOT NULL,
PRIMARY KEY (`feed_id`, `stream_id`)
if(!LADDLUtils::existTable($conn, $posts_table)) {
CREATE TABLE `{$posts_table}`
`feed_id` VARCHAR(20) NOT NULL,
`post_id` VARCHAR(50) NOT NULL,
`post_type` VARCHAR(10) NOT NULL,
`post_permalink` VARCHAR(300),
`post_header` VARCHAR(200){$charset_collate},
`user_nickname` VARCHAR(100){$charset_collate},
`user_screenname` VARCHAR(200){$charset_collate},
`user_pic` VARCHAR(300) NOT NULL,
`user_link` VARCHAR(300),
`user_counts_follows` INT,
`user_counts_followed_by` INT,
`creation_index` INT NOT NULL DEFAULT 0,
`image_url` VARCHAR(500),
`media_url` VARCHAR(500),
`media_type` VARCHAR(100),
PRIMARY KEY (`post_id`, `post_type`, `feed_id`)