-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Description
We have the topic syncronization tool, but not a post sync.
Can this code for topic be changed to work for posts?
`
case 'sync_url':
$sync_url = $this->request->variable('sync', '');
$redirect_url = "{$phpbb_admin_path}index.$phpEx?i=-phpbbseo-usu-acp-usu&mode=sync_url";
$go = max(0, $this->request->variable('go', 0));
if ($cancel || !$go)
{
trigger_error($this->user->lang['SYNC_WARN'] . '<br/><br/><b> • <a href="' . append_sid($redirect_url, "go=1&sync=sync") . '">' . $this->user->lang['SYNC_TOPIC_URLS'] . '</a><br/><br/> • <a href="' . append_sid($redirect_url, "go=1&sync=reset") . '" >' . $this->user->lang['SYNC_RESET_TOPIC_URLS'] . '</a></b>');
}
$starttime = microtime(true);
$start = max(0, $this->request->variable('start', 0));
$limit = max(100, $this->request->variable('limit', 0));
// Do not go over 1000 topic in a row
$limit = min(1000, $limit);
$poll_processed = 0;
$forum_data = array();
$url_updated = 0;
if ($sync_url === 'sync')
{
// get all forum info
$sql = 'SELECT forum_id, forum_name FROM ' . FORUMS_TABLE;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$forum_data[$row['forum_id']] = $row['forum_name'];
$this->core->set_url($row['forum_name'], $row['forum_id'], $this->core->seo_static['forum']);
}
$db->sql_freeresult($result);
// let's work
$sql = 'SELECT * FROM ' . TOPICS_TABLE . '
ORDER BY topic_id ASC';
$result = $db->sql_query_limit($sql, $limit, $start);
while ($row = $db->sql_fetchrow($result))
{
$forum_id = (int) $row['forum_id'];
$topic_id = (int) $row['topic_id'];
$_parent = $row['topic_type'] == POST_GLOBAL ? $this->core->seo_static['global_announce'] : $this->core->seo_url['forum'][$forum_id];
if ( !$this->core->check_url('topic', $row['topic_url'], $_parent))
{
if (!empty($row['topic_url']))
{
// Here we get rid of the seo delim (-t) and put it back even in simple mod
// to be able to handle all cases at once
$_url = preg_replace('`' . $this->core->seo_delim['topic'] . '$`i', '', $row['topic_url']);
$_title = $this->core->get_url_info('topic', $_url . $this->core->seo_delim['topic'] . $topic_id, 'title');
}
else
{
$_title = $this->core->modrtype > 2 ? censor_text($row['topic_title']) : '';
}
unset($this->core->seo_url['topic'][$topic_id]);
$row['topic_url'] = $this->core->get_url_info('topic', $this->core->prepare_url( 'topic', $_title, $topic_id, $_parent, (( empty($_title) || ($_title == $this->core->seo_static['topic']) ) ? true : false) ), 'url');
unset($this->core->seo_url['topic'][$topic_id]);
if ($row['topic_url'])
{
// Update the topic_url field for later re-use
$sql = "UPDATE " . TOPICS_TABLE . " SET topic_url = '" . $db->sql_escape($row['topic_url']) . "'
WHERE topic_id = $topic_id";
$db->sql_query($sql);
$url_updated++;
}
}
}
$db->sql_freeresult($result);
$sql = 'SELECT count(topic_id) as topic_cnt FROM ' . TOPICS_TABLE;
$result = $db->sql_query($sql);
$cnt = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ($cnt['topic_cnt'] > ($start + $limit))
{
$endtime = microtime(true);
$duration = $endtime - $starttime;
$speed = round($limit/$duration, 2);
$percent = round((($start + $limit) / $cnt['topic_cnt']) * 100, 2);
$message = sprintf($user->lang['SYNC_PROCESSING'], $percent, ($start + $limit), $cnt['topic_cnt'], $limit, $speed, round($duration, 2) , round((($cnt['topic_cnt'] - $start)/$speed)/60, 2));
if ($url_updated)
{
$message.= sprintf($user->lang['SYNC_ITEM_UPDATED'], '<br/>' . $url_updated);
}
$new_limit = ($duration < 10) ? $limit + 50 : $limit - 10;
meta_refresh(1, append_sid($redirect_url, 'go=1&start=' . ($start + $limit) . "&limit=$new_limit&sync=sync"));
trigger_error("$message<br/>");
}
else
{
trigger_error($user->lang['SYNC_COMPLETE'] . sprintf($user->lang['RETURN_INDEX'], '<br/><br/><a href="' . append_sid($redirect_url) . '" >', '</a>'));
}
}`
Metadata
Metadata
Assignees
Labels
No labels