| | |
| | | $args = []; |
| | | foreach ($data as $key => $value) { |
| | | switch ($key) { |
| | | case 'depends_on': |
| | | if (is_string($value) && !empty($value)) { |
| | | $args['depends_on'] = sanitize_text_field($value); |
| | | } |
| | | break; |
| | | case 'item_id': |
| | | if (is_numeric($value)) { |
| | | $args['item_id'] = absint($value); |
| | |
| | | ); |
| | | |
| | | if ($args['mode'] !== 'selection') { |
| | | $dependencies = [$args['upload']]; |
| | | if (!empty($args['depends_on'])) { |
| | | $dependencies[] = $args['depends_on']; |
| | | } |
| | | |
| | | JVB()->queue()->queueOperation( |
| | | 'attach_upload_to_content', |
| | | $args['user'], |
| | |
| | | [ |
| | | 'priority' => 'high', |
| | | 'operation_id' => $args['id'], |
| | | 'depends_on' => $args['upload'] |
| | | 'depends_on' => $dependencies |
| | | ] |
| | | ); |
| | | } |
| | |
| | | throw new Exception('No upload results found for operation: ' . $data['upload']); |
| | | } |
| | | |
| | | if (empty($data['post_id']) || str_starts_with((string)($data['item_id'] ?? ''), 'new')) { |
| | | foreach ($operation->dependencies as $depId) { |
| | | $dep = JVB()->queue()->get($depId); |
| | | if ($dep && $dep->type === 'content_update' && !empty($dep->result['new_posts'])) { |
| | | $itemId = $data['item_id'] ?? null; |
| | | if ($itemId && isset($dep->result['new_posts'][$itemId])) { |
| | | $data['post_id'] = $dep->result['new_posts'][$itemId]; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (empty($data['post_id'])) { |
| | | throw new Exception('Could not resolve post_id from dependencies'); |
| | | } |
| | | } |
| | | |
| | | // Now attach to the specified content |
| | | if (!empty($data['field_name'])) { |
| | | $this->updateFieldValue($data, $upload_results); |