diff --git a/admin_console/configs/navigation.xml b/admin_console/configs/navigation.xml index c9cc3ad8709..427b525acec 100644 --- a/admin_console/configs/navigation.xml +++ b/admin_console/configs/navigation.xml @@ -115,6 +115,11 @@ index entry-restoration + + + index + copy-conversion-profile + index diff --git a/admin_console/controllers/IndexController.php b/admin_console/controllers/IndexController.php index 260ef148717..485626950e2 100644 --- a/admin_console/controllers/IndexController.php +++ b/admin_console/controllers/IndexController.php @@ -88,6 +88,67 @@ public function kelloggsAction() $settings->sessionExpiry); } + public function copyConversionProfileAction() + { + $request = $this->getRequest(); + $form = new Form_CopyConversionProfile(); + $action = $this->view->url(array('controller' => 'index', 'action' => 'copy-conversion-profile'), null, true); + $form->setAction($action); + $this->view->copyConversionProfileForm = $form; + $this->view->copyResult = null; + + if (!$request->isPost()) { + return; + } + + $post = $request->getPost(); + if (!$form->isValid($post)) { + return; + } + + $conversionProfileId = (int)$form->getValue('conversion_profile_id'); + $destPartnerId = (int)$form->getValue('dest_partner_id'); + + $scriptPath = realpath(APPLICATION_PATH . '/../alpha/scripts/utils/copyConversionProfile.php'); + if (!$scriptPath || !file_exists($scriptPath)) { + $this->view->copyResult = array( + 'success' => false, + 'message' => 'Could not locate copyConversionProfile.php script.', + ); + return; + } + + $cmd = sprintf( + 'php %s %s %s realrun 2>&1', + escapeshellarg($scriptPath), + escapeshellarg($conversionProfileId), + escapeshellarg($destPartnerId) + ); + + $output = shell_exec($cmd); + + $newId = null; + $systemName = null; + if (preg_match('/^COPY_SUCCESS new_id=(\d+) system_name=(.*)$/m', $output, $matches)) { + $newId = $matches[1]; + $systemName = trim($matches[2]); + } + + if ($newId !== null) { + $this->view->copyResult = array( + 'success' => true, + 'newId' => $newId, + 'systemName' => $systemName, + 'message' => "Successfully copied conversion profile {$conversionProfileId} (system name: {$systemName}) from partner 0 to partner {$destPartnerId}. New profile ID: {$newId}.", + ); + } else { + $this->view->copyResult = array( + 'success' => false, + 'message' => 'Script error: ' . htmlspecialchars(trim($output)), + ); + } + } + public function entryRestorationAction() { $request = $this->getRequest(); diff --git a/admin_console/forms/CopyConversionProfile.php b/admin_console/forms/CopyConversionProfile.php new file mode 100644 index 00000000000..08ae5c4a995 --- /dev/null +++ b/admin_console/forms/CopyConversionProfile.php @@ -0,0 +1,43 @@ +setMethod('post'); + $this->setAttrib('id', 'frmCopyConversionProfile'); + + $this->setDecorators(array( + 'FormElements', + array('HtmlTag', array('tag' => 'fieldset')), + 'Form', + )); + + $conversionProfileId = new Zend_Form_Element_Text('conversion_profile_id'); + $conversionProfileId->setLabel('Conversion Profile ID (from partner 0)') + ->setRequired(true) + ->addFilter('StripTags') + ->addFilter('StringTrim') + ->addValidator('Digits') + ->setDecorators(array('ViewHelper', 'Errors', 'Label', array('HtmlTag', array('tag' => 'div', 'class' => 'form-field')))); + $this->addElement($conversionProfileId); + + $destPartnerId = new Zend_Form_Element_Text('dest_partner_id'); + $destPartnerId->setLabel('Destination Partner ID') + ->setRequired(true) + ->addFilter('StripTags') + ->addFilter('StringTrim') + ->addValidator('Digits') + ->setDecorators(array('ViewHelper', 'Errors', 'Label', array('HtmlTag', array('tag' => 'div', 'class' => 'form-field')))); + $this->addElement($destPartnerId); + + $this->addElement('button', 'cmdSubmit', array( + 'type' => 'submit', + 'label' => 'Copy Conversion Profile', + 'decorators' => array('ViewHelper', array('HtmlTag', array('tag' => 'div', 'class' => 'form-field'))), + )); + } +} \ No newline at end of file diff --git a/admin_console/views/scripts/index/copy-conversion-profile.phtml b/admin_console/views/scripts/index/copy-conversion-profile.phtml new file mode 100644 index 00000000000..d99977bb867 --- /dev/null +++ b/admin_console/views/scripts/index/copy-conversion-profile.phtml @@ -0,0 +1,72 @@ + + +

Copy Static Conversion Profile from Partner 0

+ +

This tool copies a static conversion profile from partner 0 to a given partner, including all its asset params rows.

+ +copyResult): ?> +
+ escape($this->copyResult['message']); ?> +copyResult['success']): ?> + + + + + + + + + +
New Profile ID:
System Name:
+ +
+ + +copyConversionProfileForm; ?> \ No newline at end of file diff --git a/alpha/scripts/utils/copyConversionProfile.php b/alpha/scripts/utils/copyConversionProfile.php index 5a87544cf88..b457992c5ad 100644 --- a/alpha/scripts/utils/copyConversionProfile.php +++ b/alpha/scripts/utils/copyConversionProfile.php @@ -21,6 +21,12 @@ $conversionProfileId = $argv[1]; $destPartnerId = $argv[2]; +$destPartner = PartnerPeer::retrieveByPK($destPartnerId); +if (is_null($destPartner)) +{ + die("Partner {$destPartnerId} does not exist" . PHP_EOL); +} + $conversionProfile = conversionProfile2Peer::retrieveByPKAndPartnerId($conversionProfileId, 0); if (is_null($conversionProfile) || $conversionProfile->getStatus() == ConversionProfileStatus::DISABLED) @@ -48,6 +54,8 @@ { KalturaLog::debug("Could not copy flavor params {$flavorParamsConversionProfile->getId()} from conversion profile {$conversionProfile->getId()}, exception: {$exception->getMessage()}"); } + + echo "COPY_SUCCESS new_id={$newConversionProfile->getId()} system_name=" . $conversionProfile->getSystemName() . PHP_EOL; } catch (Exception $exception) { diff --git a/configurations/admin.template.ini b/configurations/admin.template.ini index f92c445ba2c..13e0dcdd32e 100644 --- a/configurations/admin.template.ini +++ b/configurations/admin.template.ini @@ -1344,6 +1344,7 @@ access.user.logout = * access.user.reset-password = * access.user.reset-password-link = * access.index = * +access.index.copy-conversion-profile = SYSTEM_ADMIN_PUBLISHER_CONFIG ;access.accounts = ps access.partner.all = SYSTEM_ADMIN_PUBLISHER_BASE