Jake Vanderwerf
2025-10-18 b0194e10a87e16797a568d8a30d53ebecd27d8a4
inc/managers/OperationQueue.php
@@ -604,6 +604,12 @@
   protected function deepMerge(array $existing, array $new): array
   {
      $merged = $existing;
      if (!$this->isAssociativeArray($existing) && !$this->isAssociativeArray($new)) {
         error_log('It is an associative array!');
         return array_merge($existing, $new);
      }
      error_log('Not an associative array... moving on!');
      foreach ($new as $key => $newValue) {
         if (!array_key_exists($key, $existing)) {
            $merged[$key] = $newValue;
@@ -614,9 +620,16 @@
                  // Recursive merge going deeper, if any of them are associative arrays
                  $merged[$key] = $this->deepMerge($existingValue, $newValue);
               } else {
                  // Unique merge if indexed arrays
                  $containsComplex = $this->containsComplexData($existingValue) || $this->containsComplexData($newValue);
                  if ($containsComplex) {
                     // Just merge and re-index - preserves all items from chunks
                     $merged[$key] = array_values(array_merge($existingValue, $newValue));
                  } else {
                     // Simple scalar arrays - use unique merge
                  $merged[$key] = array_unique(array_merge($existingValue, $newValue), SORT_REGULAR);
               }
               }
            } elseif (is_array($existingValue) && !is_array($newValue)) {
               // The existing value is an array, but the new one isn't
               // Check if it's safe to use in_array (only if existing doesn't contain arrays)
@@ -663,6 +676,21 @@
      return array_keys($arr) !== range(0, count($arr) - 1);
   }
   /**
    * Check if an array contains complex data (arrays or objects)
    * @param array $arr
    * @return bool
    */
   protected function containsComplexData(array $arr): bool
   {
      foreach ($arr as $item) {
         if (is_array($item) || is_object($item)) {
            return true;
         }
      }
      return false;
   }
   protected function getEarliestScheduledTime(string $existing, string $new): string
   {
      $existing_time = strtotime($existing);
@@ -1264,8 +1292,11 @@
               $filterResult['result'] = [$filterResult['result']];
            }
            // Store the result data
            error_log('Merging Old Result: '. print_r($oldResult, true));
            error_log('With Newer Result: '. print_r($filterResult['result'], true));
            $resultToStore = $this->deepMerge($oldResult, $filterResult['result']);
            error_log('Merged Result: '.print_r($resultToStore, true));
            $resultToStore['processed_at'] = current_time('mysql');