public function duplicate($new_name)
 {
     $id = parent::duplicate($new_name);
     if (-1 == $id) {
         return $id;
     }
     require_once NELIOAB_EXP_CONTROLLERS_DIR . '/widget-experiment-controller.php';
     require_once NELIOAB_MODELS_DIR . '/experiments-manager.php';
     /** @var NelioABMenuAlternativeExperiment $exp */
     $exp = NelioABExperimentsManager::get_experiment_by_id($id, $this->get_type());
     $alts_src = $this->get_alternatives();
     $alts_dest = $exp->get_alternatives();
     for ($i = 0; $i < count($alts_src); ++$i) {
         /** @var NelioABAlternative $alt_src */
         $alt_src = $alts_src[$i];
         /** @var NelioABAlternative $alt_dest */
         $alt_dest = $alts_dest[$i];
         NelioABWidgetExpAdminController::duplicate_widgets($this->get_id(), $alt_src->get_id(), $exp->get_id(), $alt_dest->get_id());
     }
     return $id;
 }
 public function duplicate($new_name)
 {
     $id = parent::duplicate($new_name);
     if (-1 == $id) {
         return $id;
     }
     require_once NELIOAB_EXP_CONTROLLERS_DIR . '/menu-experiment-controller.php';
     $controller = NelioABMenuExpAdminController::get_instance();
     require_once NELIOAB_MODELS_DIR . '/experiments-manager.php';
     /** @var NelioABMenuAlternativeExperiment $exp */
     $exp = NelioABExperimentsManager::get_experiment_by_id($id, $this->get_type());
     $alts = 0;
     $controller->begin();
     foreach ($exp->get_alternatives() as $alt) {
         /** @var NelioABAlternative $alt */
         $menu_id = $controller->duplicate_menu_and_create_alternative($alt->get_value(), $exp->get_id());
         $body = array('value' => $menu_id);
         try {
             NelioABBackend::remote_post(sprintf(NELIOAB_BACKEND_URL . '/alternative/%s/update', $alt->get_id()), $body);
             $alts++;
         } catch (Exception $e) {
         }
     }
     $controller->commit();
     if (0 == $alts) {
         $exp->set_status(NelioABExperiment::STATUS_DRAFT);
     }
     $exp->save();
     return $exp->get_id();
 }