public static function createImageCache() { \Session::flash('rawArray', 1); $db = \DB::getMongoDB(); $db = $db->temp; // \Queue::push('Queues\UpdateUnits', Entity::whereIn('documentType', ['painting', 'drawing', 'picture'])->lists('_id')); $result = Entity::whereIn('documentType', ['painting', 'drawing', 'picture'])->get()->toArray(); if (count($result) > 0) { foreach ($result as &$parent) { $children = Entity::whereIn('parents', [$parent['_id']])->get(['recognizedFeatures', 'content.features'])->toArray(); $parent['content']['features'] = []; $parent['totalRelevantFeatures'] = 0; foreach ($children as $child) { if (isset($child['recognizedFeatures'])) { $parent['totalRelevantFeatures'] = $parent['totalRelevantFeatures'] + count($child['recognizedFeatures']); } if (isset($child['content']['features'])) { if (is_array($child['content']['features'])) { foreach ($child['content']['features'] as $k => $v) { if (array_key_exists($k, $parent['content']['features'])) { if (!is_array($parent['content']['features'][$k])) { $parent['content']['features'][$k] = [$parent['content']['features'][$k]]; } if (is_array($v)) { foreach ($v as $vit) { array_push($parent['content']['features'][$k], $vit); } } } else { $parent['content']['features'][$k] = $v; } } } } // $featureKey = key($child['content']['features']); // if(!isset($parent['content']['features'][$featureKey])) // { // $parent['content']['features'][$featureKey] = []; // if(is_array($child['content']['features'][$featureKey])) // { // foreach($child['content']['features'][$featureKey] as $k => $v) // { // $parent['content']['features'][$featureKey][$k] = $v; // } // } // } // else { // if(is_array($child['content']['features'][$featureKey])) // { // foreach($child['content']['features'][$featureKey] as $k => $v) // { // $parent['content']['features'][$featureKey][$k] = $v; // } // } // else // { // $parent['content']['features'][$featureKey] = $child['content']['features'][$featureKey]; // } // } } } try { Temp::whereIn('documentType', ['painting', 'drawing', 'picture'])->forceDelete(); $db->batchInsert($result, array('continueOnError' => true)); } catch (Exception $e) { // ContinueOnError will still throw an exception on duplication, even though it continues, so we just move on. } } \Session::forget('rawArray'); }