csrfProtection(); // Get the reference to the uploaded file $file = $_FILES['importfile']; // Get a URL router $router = $this->container->router; if (isset($file['name'])) { // Load the file data $data = file_get_contents($file['tmp_name']); @unlink($file['tmp_name']); // JSON decode $data = json_decode($data, true); // Check for data validity $isValid = is_array($data) && !empty($data); if ($isValid) { $isValid = $isValid && array_key_exists('description', $data); } if ($isValid) { $isValid = $isValid && array_key_exists('configuration', $data); } if ($isValid) { $isValid = $isValid && array_key_exists('filters', $data); } if (!$isValid) { $this->setRedirect($router->route('index.php?view=profiles'), Text::_('COM_AKEEBA_PROFILES_ERR_IMPORT_INVALID'), 'error'); return; } // Unset the id, if it exists if (array_key_exists('id', $data)) { unset($data['id']); } // Try saving the profile /** @var DataModel $model */ $model = $this->getModel(); $result = $model->create($data); if ($result) { $this->setRedirect($router->route('index.php?view=profiles'), Text::_('COM_AKEEBA_PROFILES_MSG_IMPORT_COMPLETE')); } else { $this->setRedirect($router->route('index.php?view=profiles'), Text::_('COM_AKEEBA_PROFILES_ERR_IMPORT_FAILED'), 'error'); } } else { $this->setRedirect($router->route('index.php?view=profiles'), Text::_('MSG_UPLOAD_INVALID_REQUEST'), 'error'); } } }