Fixed Nondeterministic sorting during code extension, code event listener and template modification rebuilds

Affected version
2.1.17

Xon

Well-known member
When the execution order for a code extension or code event listener is the same, potential nondeterministic sorting between XF installs;

PHP:
public function getExtensionCacheData()
{
   $extensions = $this->finder('XF:ClassExtension')
      ->whereAddOnActive(['disableProcessing' => true])
      ->where('active', 1)
      ->order(['execute_order'])
      ->fetch();
...

PHP:
public function getListenerCacheData()
{
   $listeners = $this->finder('XF:CodeEventListener')
      ->whereAddOnActive(['disableProcessing' => true])
      ->where('active', 1)
      ->order(['event_id', 'execute_order'])
      ->fetch();

   $cache = [];
...
PHP:
public function applyModificationsToTemplate($type, $title, $template, &$status = [])
{
   $modifications = $this->finder('XF:TemplateModification')
      ->where([
         'type' => $type,
         'template' => $title,
         'enabled' => 1
      ])
      ->whereAddOnActive()
      ->order('execution_order')
      ->fetch();
...

If execute_order/execution_order has duplicate values, what happens is the rows with duplicate values tend to be sorted by the primary id which is a proxy for install order. However the sorting by primary id isn't guaranteed, and is different across installs.

This means the interaction between various add-ons can be non-deterministic depending on the install order, which is a very unexpected experience.

Especially as these don't match findTemplateModificationsForList, findExtensionsForList, findListenersForList sorting behaviour.

findExtensionsForList should probably include execution_order in it's sort.
 

XF Bug Bot

XenForo bug fixer bot
Staff member
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.1.8).

Change log:
Ensure more consistent sorting is used for class extensions, code event listeners and template modifications.
There may be a delay before changes are rolled out to the XenForo Community.
 
Top