Skip to content

Commit

Permalink
Fix search when some corrupt addons do not have a revision
Browse files Browse the repository at this point in the history
  • Loading branch information
vampy committed Oct 30, 2017
1 parent 4390e19 commit 69bd03b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
26 changes: 22 additions & 4 deletions include/Addon.class.php
Expand Up @@ -163,12 +163,15 @@ private function loadRevisions()
}
catch (DBException $e)
{
throw new AddonException(exception_message_db(_('load revisions')));
throw new AddonException(exception_message_db(_('load revisions')), ErrorType::ADDON_DB_EXCEPTION);
}

if (!$revisions)
{
throw new AddonException(_h('No revisions of this add-on exist. This should never happen.'));
throw new AddonException(
_h('No revisions of this add-on exist. This should never happen.'),
ErrorType::ADDON_REVISION_MISSING
);
}

foreach ($revisions as $rev)
Expand Down Expand Up @@ -1539,7 +1542,7 @@ public static function filterMenuTemplate($addons, $current_id = null)
{
$class = '';
}
elseif ($has_permission || $addon->isUserOwner())
else if ($has_permission || $addon->isUserOwner())
{
// not approved, see of we are logged in and we have permission
$class = ' disabled';
Expand Down Expand Up @@ -1653,7 +1656,22 @@ public static function search($search_query, $type, array $search_flags)
$return_addons = [];
foreach ($addons as $addon)
{
$return_addons[] = new static($addon);
try
{
$return_addons[] = new static($addon);
}
catch (AddonException $e)
{
if ($e->getCode() == ErrorType::ADDON_REVISION_MISSING)
{
// ignore corrupt addon
Debug::addMessage("No revision for addon = " . $addon['name']);
}
else
{
throw $e;
}
}
}

return $return_addons;
Expand Down
3 changes: 3 additions & 0 deletions include/Exceptions.class.php
Expand Up @@ -48,6 +48,9 @@ class ErrorType extends \MyCLabs\Enum\Enum
const USER_SENDING_CREATE_EMAIL = 78; // while sending create account email
const USER_INACTIVE_ACCOUNT = 79; // account is not active

const ADDON_DB_EXCEPTION = 100; // a generic database exception occurred while querying some addon data
const ADDON_REVISION_MISSING = 101; // the addon Revision is missing, corrupt

const VALIDATE_NOT_IN_CHAR_RANGE = 500; // string is not in min/max char string range
const VALIDATE_PASSWORDS_MATCH = 501; // passwords do not match

Expand Down

0 comments on commit 69bd03b

Please sign in to comment.