fetchAll($query); $query = "UPDATE `aux_lock_rules` SET `attributes` = :attributes, `sorting` = :sorting WHERE `lock_id` = :id"; $statement = DBManager::get()->prepare($query); foreach ($rows as $row) { $attributes = json_decode($row['attributes'], true) ?: []; $attributes = array_filter($attributes); $attributes = array_keys($attributes); $sorting = json_decode($row['sorting'], true) ?: []; $sorting = array_filter($sorting, function ($id) use ($attributes) { return in_array($id, $attributes); }, ARRAY_FILTER_USE_KEY); $statement->bindValue(':id', $row['lock_id']); $statement->bindValue(':attributes', json_encode($attributes)); $statement->bindValue(':sorting', json_encode($sorting)); $statement->execute(); } } protected function down() { $query = "SELECT `lock_id`, `attributes` FROM `aux_lock_rules`"; $rows = DBManager::get()->fetchAll($query); $query = "UPDATE `aux_lock_rules` SET `attributes` = :attributes WHERE `lock_id` = :id"; $statement = DBManager::get()->prepare($query); foreach ($rows as $row) { $attributes = json_decode($row['attributes'], true) ?: []; $attributes = array_fill_keys($attributes, '1'); $statement->bindValue(':id', $row['lock_id']); $statement->bindValue(':attributes', json_encode($attributes)); $statement->execute(); } } }