Permalink
Browse files

Merge pull request #1558 from pjwiseman/25663

CMS [#25663] Fixes build admin menu item error while (re)installing componen...
  • Loading branch information...
2 parents d50fe07 + 486b4bb commit 963588cfdbede8d22161969687d1fd7e5551f526 @pasamio pasamio committed Oct 2, 2012
Showing with 39 additions and 3 deletions.
  1. +39 −3 libraries/joomla/installer/adapters/component.php
@@ -1267,9 +1267,45 @@ protected function _buildAdminMenus()
if (!$table->bind($data) || !$table->check() || !$table->store())
{
- // Install failed, warn user and rollback changes
- JLog::add($table->getError(), JLog::WARNING, 'jerror');
- return false;
+ // The menu item already exists. Delete it and retry instead of throwing an error.
+ $query = $db->getQuery(true);
+ $query->select('id');
+ $query->from('#__menu');
+ $query->where('menutype = ' . $db->quote('main'));
+ $query->where('client_id = 1');
+ $query->where('link = ' . $db->quote('index.php?option=' . $option));
+ $query->where('type = ' . $db->quote('component'));
+ $query->where('parent_id = 1');
+ $query->where('home = 0');
+
+ $db->setQuery($query);
+ $menu_id = $db->loadResult();
+
+ if (!$menu_id)
+ {
+ // Oops! Could not get the menu ID. Go back and rollback changes.
+ JError::raiseWarning(1, $table->getError());
+ return false;
+ }
+ else
+ {
+ // Remove the old menu item
+ $query = $db->getQuery(true);
+ $query->delete('#__menu');
+ $query->where('id = ' . (int) $menu_id);
+
+ $db->setQuery($query);
+ $db->query();
+
+ // Retry creating the menu item
+ $table->setLocation(1, 'last-child');
+ if (!$table->bind($data) || !$table->check() || !$table->store())
+ {
+ // Install failed, warn user and rollback changes
+ JError::raiseWarning(1, $table->getError());
+ return false;
+ }
+ }
}
/*

0 comments on commit 963588c

Please sign in to comment.