Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

fix(images): add a hotfix to replace image URLs after datastore migra…

…tion
  • Loading branch information...
hypeJunction committed Jun 26, 2017
1 parent 8b1eef4 commit 15a18858f667fe160f52c8cec96a6ba1848c55cf
Showing with 84 additions and 0 deletions.
  1. +53 −0 actions/admin/scraper/timestamp_images.php
  2. +7 −0 languages/en.php
  3. +10 −0 start.php
  4. +14 −0 views/default/admin/scraper/hotfixes.php
@@ -0,0 +1,53 @@
<?php
set_time_limit(0);
$getter = function($options) {
$limit = (int) elgg_extract('limit', $options, 10);
$offset = (int) elgg_extract('offset', $options, 0);
$dbprefix = elgg_get_config('dbprefix');
$query = "
SELECT * FROM {$dbprefix}scraper_data
LIMIT $offset, $limit
";
return get_data($query);
};
$svc = \hypeJunction\Scraper\ScraperService::getInstance();
$batch = new ElggBatch($getter, [
'limit' => 0,
]);
$i = 0;
foreach ($batch as $row) {
$data = unserialize($row->data);
$thumbnail_url = elgg_extract('thumbnail_url', $data);
if (!$thumbnail_url) {
continue;
}
if (!preg_match('~.*/serve-file/e(\d+)/l(\d+)/d([ia])/c([01])/([a-zA-Z0-9\-_]+)/\d+/(\d+)/(.*)$~', $thumbnail_url, $m)) {
continue;
}
list(, $expires, $last_updated, $disposition, $use_cookie, $mac, $owner_guid, $filename) = $m;
$file = new ElggFile();
$file->owner_guid = $owner_guid;
$file->setFilename($filename);
$data['thumbnail_url'] = elgg_get_inline_url($file);
if ($thumbnail_url != $data['thumbnail_url']) {
$svc->save($row->url, $data);
$i++;
}
}
return elgg_ok_response(elgg_echo('admin:scraper:timestamp_images:updated', [$i]));
@@ -38,4 +38,11 @@
'admin:scraper:cache:clear' => 'Clear Cache',
'admin:scraper:cache:no_results' => 'No URLs were cached in this domain',
'admin:scraper:hotfixes' => 'Hotfixes',
'admin:scraper:hotfix' => 'Fix',
'admin:scraper:timestamp_images' => 'Image timestamp hotfix',
'admin:scraper:timestamp_images:help' => 'Image previews served from data store require a persistent file timestamp. If timestamps of files has changed, e.g. after a migration to a new server, run this script to fix the issues',
'admin:scraper:timestamp_images:updated' => 'Timestamp change detected in %s files. URLs have been updated',
];
@@ -42,6 +42,7 @@
elgg_register_action('admin/scraper/edit', __DIR__ . '/actions/admin/scraper/edit.php', 'admin');
elgg_register_action('admin/scraper/refetch', __DIR__ . '/actions/admin/scraper/refetch.php', 'admin');
elgg_register_action('admin/scraper/clear', __DIR__ . '/actions/admin/scraper/clear.php', 'admin');
elgg_register_action('admin/scraper/timestamp_images', __DIR__ . '/actions/admin/scraper/timestamp_images.php', 'admin');
// Admin
elgg_register_menu_item('page', array(
@@ -60,6 +61,15 @@
'section' => 'develop'
));
elgg_register_menu_item('page', array(
'name' => 'scraper:hotfixes',
'href' => 'admin/scraper/hotfixes',
'text' => elgg_echo('admin:scraper:hotfixes'),
'context' => 'admin',
'section' => 'develop'
));
elgg_register_ajax_view('output/card');
});
@@ -0,0 +1,14 @@
<?php
$title = elgg_echo('admin:scraper:timestamp_images');
$body = elgg_format_element('p', [], elgg_echo('admin:scraper:timestamp_images:help'));
$footer = elgg_view('output/url', [
'text' => elgg_echo('admin:scraper:hotfix'),
'href' => 'action/admin/scraper/timestamp_images',
'is_action' => true,
'class' => 'elgg-button elgg-button-action',
]);
echo elgg_view_module('info', $title, $body, [
'footer' => $footer,
]);

0 comments on commit 15a1885

Please sign in to comment.
You can’t perform that action at this time.