From d27b7627a545cf882d007bfc3966e229ad9aa39f Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 12 Oct 2011 17:03:43 -0400 Subject: [PATCH] more robust handling of bad data in offline backup queue handler --- .../offlinebackupqueuehandler.php | 89 ++++++++++++------- 1 file changed, 56 insertions(+), 33 deletions(-) diff --git a/plugins/OfflineBackup/offlinebackupqueuehandler.php b/plugins/OfflineBackup/offlinebackupqueuehandler.php index 054c4d403c..2de6c9a667 100644 --- a/plugins/OfflineBackup/offlinebackupqueuehandler.php +++ b/plugins/OfflineBackup/offlinebackupqueuehandler.php @@ -126,11 +126,16 @@ class OfflineBackupQueueHandler extends QueueHandler $notice = $stream->getNotices(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); while ($notice->fetch()) { - $fname = $dir . '/'. common_date_iso8601($notice->created) . '-notice-' . $notice->id . '.atom'; - $data = $notice->asAtomEntry(false, false, false, null); - common_log(LOG_INFO, 'dumping notice ' . $notice->id . ' to file ' . $fname); - file_put_contents($fname, $data); - $data = null; + try { + $fname = $dir . '/'. common_date_iso8601($notice->created) . '-notice-' . $notice->id . '.atom'; + $data = $notice->asAtomEntry(false, false, false, null); + common_log(LOG_INFO, 'dumping notice ' . $notice->id . ' to file ' . $fname); + file_put_contents($fname, $data); + $data = null; + } catch (Exception $e) { + common_log(LOG_ERR, "Error backing up notice " . $notice->id . ": " . $e->getMessage()); + continue; + } } $page++; @@ -148,12 +153,17 @@ class OfflineBackupQueueHandler extends QueueHandler $fave = Fave::byProfile($user->id, ($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); while ($fave->fetch()) { - $fname = $dir . '/'. common_date_iso8601($fave->modified) . '-fave-' . $fave->notice_id . '.atom'; - $act = $fave->asActivity(); - $data = $act->asString(false, false, false); - common_log(LOG_INFO, 'dumping fave of ' . $fave->notice_id . ' to file ' . $fname); - file_put_contents($fname, $data); - $data = null; + try { + $fname = $dir . '/'. common_date_iso8601($fave->modified) . '-fave-' . $fave->notice_id . '.atom'; + $act = $fave->asActivity(); + $data = $act->asString(false, false, false); + common_log(LOG_INFO, 'dumping fave of ' . $fave->notice_id . ' to file ' . $fname); + file_put_contents($fname, $data); + $data = null; + } catch (Exception $e) { + common_log(LOG_ERR, "Error backing up fave of " . $fave->notice_id . ": " . $e->getMessage()); + continue; + } } $page++; @@ -171,15 +181,20 @@ class OfflineBackupQueueHandler extends QueueHandler $sub = Subscription::bySubscriber($user->id, ($page-1)*PROFILES_PER_PAGE, PROFILES_PER_PAGE + 1); while ($sub->fetch()) { - if ($sub->subscribed == $user->id) { + try { + if ($sub->subscribed == $user->id) { + continue; + } + $fname = $dir . '/'. common_date_iso8601($sub->created) . '-subscription-' . $sub->subscribed . '.atom'; + $act = $sub->asActivity(); + $data = $act->asString(false, false, false); + common_log(LOG_INFO, 'dumping sub of ' . $sub->subscribed . ' to file ' . $fname); + file_put_contents($fname, $data); + $data = null; + } catch (Exception $e) { + common_log(LOG_ERR, "Error backing up subscription to " . $sub->subscribed . ": " . $e->getMessage()); continue; } - $fname = $dir . '/'. common_date_iso8601($sub->created) . '-subscription-' . $sub->subscribed . '.atom'; - $act = $sub->asActivity(); - $data = $act->asString(false, false, false); - common_log(LOG_INFO, 'dumping sub of ' . $sub->subscribed . ' to file ' . $fname); - file_put_contents($fname, $data); - $data = null; } $page++; @@ -197,15 +212,20 @@ class OfflineBackupQueueHandler extends QueueHandler $sub = Subscription::bySubscribed($user->id, ($page-1)*PROFILES_PER_PAGE, PROFILES_PER_PAGE + 1); while ($sub->fetch()) { - if ($sub->subscriber == $user->id) { + try { + if ($sub->subscriber == $user->id) { + continue; + } + $fname = $dir . '/'. common_date_iso8601($sub->created) . '-subscriber-' . $sub->subscriber . '.atom'; + $act = $sub->asActivity(); + $data = $act->asString(false, true, false); + common_log(LOG_INFO, 'dumping sub by ' . $sub->subscriber . ' to file ' . $fname); + file_put_contents($fname, $data); + $data = null; + } catch (Exception $e) { + common_log(LOG_ERR, "Error backing up subscription from " . $sub->subscriber . ": " . $e->getMessage()); continue; } - $fname = $dir . '/'. common_date_iso8601($sub->created) . '-subscriber-' . $sub->subscriber . '.atom'; - $act = $sub->asActivity(); - $data = $act->asString(false, true, false); - common_log(LOG_INFO, 'dumping sub by ' . $sub->subscriber . ' to file ' . $fname); - file_put_contents($fname, $data); - $data = null; } $page++; @@ -224,18 +244,21 @@ class OfflineBackupQueueHandler extends QueueHandler $mem = Group_member::byMember($user->id, ($page-1)*GROUPS_PER_PAGE, GROUPS_PER_PAGE + 1); while ($mem->fetch()) { - $fname = $dir . '/'. common_date_iso8601($mem->created) . '-membership-' . $mem->group_id . '.atom'; - $act = $mem->asActivity(); - $data = $act->asString(false, false, false); - common_log(LOG_INFO, 'dumping membership in ' . $mem->group_id . ' to file ' . $fname); - file_put_contents($fname, $data); - $data = null; + try { + $fname = $dir . '/'. common_date_iso8601($mem->created) . '-membership-' . $mem->group_id . '.atom'; + $act = $mem->asActivity(); + $data = $act->asString(false, false, false); + common_log(LOG_INFO, 'dumping membership in ' . $mem->group_id . ' to file ' . $fname); + file_put_contents($fname, $data); + $data = null; + } catch (Exception $e) { + common_log(LOG_ERR, "Error backing up membership in " . $mem->group_id . ": " . $e->getMessage()); + continue; + } } $page++; - common_debug("Got " . $mem->N . " results on search for groups."); - } while ($mem->N > GROUPS_PER_PAGE); } -- 2.39.5