Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSVAMB-48298 -> Change entry properties using input of CSV #12733

Open
wants to merge 2 commits into
base: Tucana-20.12.0
Choose a base branch
from
Open
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
75 changes: 75 additions & 0 deletions alpha/scripts/utils/setEntryProperties.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

if($argc < 3)
{
echo "Arguments missing.\n\n";
echo "Usage: php " . __FILE__ . " {mapping} {isDateString} <realrun / dryrun> \n";
exit;
}
$mapping = $argv[1];
$isDateString = ($argv[2] === "true");
$dryRun = ($argv[3] === "dryrun");

require_once(__DIR__ . '/../bootstrap.php');


KalturaStatement::setDryRun($dryRun);

$entryMappings = file($mapping, FILE_IGNORE_NEW_LINES);

$properties = [""];
$counter = 0;
entry::setAllowOverrideReadOnlyFields(true);
foreach ($entryMappings as $entryMapping)
{
if($counter++ == 0){
$entryColumns = explode(",", $entryMapping);
foreach($entryColumns as $property){
if($property == 'id' || $property == 'entryId'){
continue;
}
if(!method_exists('entry', "set".ucfirst($property))){
echo "Property $property does not have the set function \n";
continue;
}
$properties[] = $property;
}
continue;
}
$entryValues= explode(",", $entryMapping);

$z = 0;
foreach($entryValues as $entryValue){
if($z === 0){
$z++;
$entry = entryPeer::retrieveByPK($entryValue);
if(!$entry) {
echo "Entry id [$entryValue] not found\n";
break;
}
continue;
}
if(!isset($properties[$z])){
continue;
}
$isDateValue = false;
if($isDateString){
$needles = ["createdAt", "updatedAt"];
foreach ($needles as $needle) {
if (strpos($properties[$z], $needle) === false) {
$isDateValue = true;
break;
}
}
}
$entryValue = $isDateValue ? strtotime($entryValue) : $entryValue;
/** @var $entry entry */
$entry->{"set".ucfirst($properties[$z])}($entryValue);
$entry->save();
kEventsManager::flushEvents();
kMemoryManager::clearMemory();
$z++;
}
}

KalturaLog::debug('Done');