Jump to content

Editing Packages Causes Ordering To Be Lost


Squidix Web Hosting

Recommended Posts

  1. Every time I edit a package, it breaks the ordering. Usually bumps it up to the top of the list.
  2. a. Order packages under "groups" in the admin

    b. Edit a package (change any value)

  3. No errors
  4. /clients/admin/packages/
  5. http://awesomescreenshot.com/0214qpnu6d

    http://awesomescreenshot.com/0af4qpo6e6

    http://awesomescreenshot.com/0c64qpo5e4

  6. cPanel + PHP 5.4, blesta 3.4.2, solusvm module
Link to comment
Share on other sites

It appears that when a package is edited, groups are removed and re-added? If so this should be expected behavior.

 

In edit function:

 


if (isset($vars['groups']))

$this->setGroups($package_id, $vars['groups']);


 

setGroups function:

 

private function setGroups($package_id, $groups=null) {

// Remove all existing groups

$this->Record->from("package_group")->

where("package_id", "=", $package_id)->delete();

 

// Add all given groups

if (!empty($groups) && is_array($groups)) {

for ($i=0; $i<count($groups); $i++) {

$vars = array(

'package_id'=>$package_id,

'package_group_id'=>$groups[$i]

);

$this->Record->insert("package_group", $vars);

}

}

}

Link to comment
Share on other sites

Here, I've fixed it:

 

Starting at line 305 in package model. However this is not ideal, as it won't retain ordering if a group is added (even if old groups are kept)
 
What should be done is - empty the group/package relationship table (excluding the ids of groups in the array from the submitted form), then do an array diff on the group ids, and add the new groups. that way the old relationship records are kept instead of blanked every time. since the ordering appears to be in the table for the many to many relationship between groups and packages.
 
I'll try to implement when I have some time but keep in mind I have been working with the internal code for all of 2 days now so I am not very familiar.
 
$group_ids = array();
foreach ($package->groups as $group) {
$group_ids[] = $group->id;
}
 
// Replace all group assignments with those that are given (if any given)
if (isset($vars['groups']) && $vars['groups'] != $group_ids)
$this->setGroups($package_id, $vars['groups']);
Link to comment
Share on other sites

  • 2 weeks later...
Guest
This topic is now closed to further replies.
×
×
  • Create New...