Skip to content
Browse files

[#25663] Fixes build admin menu item error while (re)installing compo…

…nent
  • Loading branch information...
1 parent d50fe07 commit cdbc3a34915eba534c8db6b726c034fbb7bc942b @pjwiseman pjwiseman committed Sep 29, 2012
Showing with 35 additions and 3 deletions.
  1. +35 −3 libraries/joomla/installer/adapters/component.php
View
38 libraries/joomla/installer/adapters/component.php
@@ -1267,9 +1267,41 @@ 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 cdbc3a3

Please sign in to comment.
Something went wrong with that request. Please try again.