Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions admin_console/configs/navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@
<controller>index</controller>
<action>entry-restoration</action>
</entry-restoration>
<copy-conversion-profile>
<label>Copy Conversion Profile</label>
<controller>index</controller>
<action>copy-conversion-profile</action>
</copy-conversion-profile>
<apc>
<label>APC</label>
<controller>index</controller>
Expand Down
61 changes: 61 additions & 0 deletions admin_console/controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
43 changes: 43 additions & 0 deletions admin_console/forms/CopyConversionProfile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* @package Admin
* @subpackage forms
*/
class Form_CopyConversionProfile extends Infra_Form
{
public function init()
{
$this->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'))),
));
}
}
72 changes: 72 additions & 0 deletions admin_console/views/scripts/index/copy-conversion-profile.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<style>
#frmCopyConversionProfile .form-field {
margin-bottom: 20px;
clear: both;
}
#frmCopyConversionProfile label {
display: block;
margin-bottom: 6px;
font-weight: bold;
font-size: 14px;
}
#frmCopyConversionProfile input[type="text"] {
display: block;
width: 300px;
padding: 8px 10px;
font-size: 14px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
#frmCopyConversionProfile input[type="text"]:focus {
border-color: #0073aa;
outline: none;
box-shadow: 0 0 4px rgba(0, 115, 170, 0.3);
}
#frmCopyConversionProfile fieldset {
border: 1px solid #ddd;
padding: 20px;
border-radius: 4px;
background: #f9f9f9;
}
.copy-cp-result {
margin-top: 20px;
padding: 15px 20px;
border-radius: 4px;
font-size: 14px;
}
.copy-cp-result.success {
background: #e8f5e9;
border: 1px solid #4caf50;
color: #2e7d32;
}
.copy-cp-result.error {
background: #fdecea;
border: 1px solid #e53935;
color: #b71c1c;
}
</style>

<h2>Copy Static Conversion Profile from Partner 0</h2>

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

<?php if ($this->copyResult): ?>
<div class="copy-cp-result <?php echo $this->copyResult['success'] ? 'success' : 'error'; ?>">
<?php echo $this->escape($this->copyResult['message']); ?>
<?php if ($this->copyResult['success']): ?>
<table style="margin-top:12px; border-collapse:collapse;">
<tr>
<td style="padding:4px 12px 4px 0; font-weight:bold;">New Profile ID:</td>
<td><input type="text" readonly value="<?php echo $this->escape($this->copyResult['newId']); ?>" style="width:120px; font-family:monospace;" onclick="this.select();" /></td>
</tr>
<tr>
<td style="padding:4px 12px 4px 0; font-weight:bold;">System Name:</td>
<td><input type="text" readonly value="<?php echo $this->escape($this->copyResult['systemName']); ?>" style="width:300px; font-family:monospace;" onclick="this.select();" /></td>
</tr>
</table>
<?php endif; ?>
</div>
<?php endif; ?>

<?php echo $this->copyConversionProfileForm; ?>
8 changes: 8 additions & 0 deletions alpha/scripts/utils/copyConversionProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions configurations/admin.template.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading