/** * @param string $entryId the new created entry * @param array $data key => value pairs */ public static function handleBulkUploadData($entryId, array $data) { KalturaLog::debug("Handle metadata bulk upload data:\n" . print_r($data, true)); if (!isset($data[self::BULK_UPLOAD_COLUMN_PROFILE_ID])) { return; } $metadataProfileId = $data[self::BULK_UPLOAD_COLUMN_PROFILE_ID]; $xmlData = null; $entry = entryPeer::retrieveByPK($entryId); if (!$entry) { return; } // $criteriaFilter = FileSyncPeer::getCriteriaFilter(); // $criteria = $criteriaFilter->getFilter(); // $criteria->add(FileSyncPeer::PARTNER_ID, $entry->getPartnerId()); $metadataProfile = MetadataProfilePeer::retrieveById($metadataProfileId); if (!$metadataProfile) { $errorMessage = "Metadata profile [{$metadataProfileId}] not found"; KalturaLog::err($errorMessage); self::addBulkUploadResultDescription($entryId, $entry->getBulkUploadId(), $errorMessage); return; } if (isset($data[self::BULK_UPLOAD_COLUMN_URL])) { try { $xmlData = file_get_contents($data[self::BULK_UPLOAD_COLUMN_URL]); KalturaLog::debug("Metadata downloaded [" . $data[self::BULK_UPLOAD_COLUMN_URL] . "]"); } catch (Exception $e) { $errorMessage = "Download metadata[" . $data[self::BULK_UPLOAD_COLUMN_URL] . "] error: " . $e->getMessage(); KalturaLog::err($errorMessage); self::addBulkUploadResultDescription($entryId, $entry->getBulkUploadId(), $errorMessage); $xmlData = null; } } elseif (isset($data[self::BULK_UPLOAD_COLUMN_XML])) { $xmlData = $data[self::BULK_UPLOAD_COLUMN_XML]; } else { $metadataProfileFields = array(); MetadataProfileFieldPeer::setUseCriteriaFilter(false); $tmpMetadataProfileFields = MetadataProfileFieldPeer::retrieveByMetadataProfileId($metadataProfileId); MetadataProfileFieldPeer::setUseCriteriaFilter(true); foreach ($tmpMetadataProfileFields as $metadataProfileField) { $metadataProfileFields[$metadataProfileField->getKey()] = $metadataProfileField; } KalturaLog::debug("Found fields [" . count($metadataProfileFields) . "] for metadata profile [{$metadataProfileId}]"); $xml = new DOMDocument(); $dataFound = false; foreach ($data as $key => $value) { if (!$value || !strlen($value)) { continue; } if (!preg_match('/^' . self::BULK_UPLOAD_COLUMN_FIELD_PREFIX . '(.+)$/', $key, $matches)) { continue; } $key = $matches[1]; if (!isset($metadataProfileFields[$key])) { $errorMessage = "Field [{$key}] does not exist"; KalturaLog::debug($errorMessage); self::addBulkUploadResultDescription($entryId, $entry->getBulkUploadId(), $errorMessage); continue; } $metadataProfileField = $metadataProfileFields[$key]; KalturaLog::debug("Found field [" . $metadataProfileField->getXpath() . "] for value [{$value}]"); $fieldValues = explode(self::BULK_UPLOAD_MULTI_VALUES_DELIMITER, $value); foreach ($fieldValues as $fieldValue) { if ($metadataProfileField->getType() == MetadataSearchFilter::KMC_FIELD_TYPE_DATE && !is_numeric($fieldValue)) { $value = self::parseFormatedDate($fieldValue); if (!$value || !strlen($value)) { $errorMessage = "Could not parse date format [{$fieldValue}] for field [{$key}]"; KalturaLog::debug($errorMessage); self::addBulkUploadResultDescription($entryId, $entry->getBulkUploadId(), $errorMessage); continue; } $fieldValue = $value; } self::addXpath($xml, $metadataProfileField->getXpath(), $fieldValue); } $dataFound = true; } if ($dataFound) { $xmlData = $xml->saveXML($xml->firstChild); $xmlData = trim($xmlData, " \n\r\t"); } } if (!$xmlData) { return; } $dbMetadata = new Metadata(); $dbMetadata->setPartnerId($entry->getPartnerId()); $dbMetadata->setMetadataProfileId($metadataProfileId); $dbMetadata->setMetadataProfileVersion($metadataProfile->getVersion()); $dbMetadata->setObjectType(Metadata::TYPE_ENTRY); $dbMetadata->setObjectId($entryId); $dbMetadata->setStatus(Metadata::STATUS_INVALID); $dbMetadata->save(); KalturaLog::debug("Metadata [" . $dbMetadata->getId() . "] saved [{$xmlData}]"); $key = $dbMetadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA); kFileSyncUtils::file_put_contents($key, $xmlData); $errorMessage = ''; $status = kMetadataManager::validateMetadata($dbMetadata, $errorMessage); if ($status == Metadata::STATUS_VALID) { kEventsManager::raiseEvent(new kObjectDataChangedEvent($dbMetadata)); } else { self::addBulkUploadResultDescription($entryId, $entry->getBulkUploadId(), $errorMessage); } }
public static function parseXml($objectType, SimpleXMLElement $scene, $partnerId, CuePoint $cuePoint) { $metadataElements = $scene->xpath('scene-customData'); if (!count($metadataElements)) { return $cuePoint; } foreach ($metadataElements as $metadataElement) { $metadata = null; $metadataProfile = null; if (isset($metadataElement['metadataId'])) { $metadata = MetadataPeer::retrieveByPK($metadataElement['metadataId']); } if ($metadata) { $metadataProfile = $metadata->getMetadataProfile(); } else { if (isset($metadataElement['metadataProfileId'])) { $metadataProfile = MetadataProfilePeer::retrieveByPK($metadataElement['metadataProfileId']); } elseif (isset($metadataElement['metadataProfile'])) { $metadataProfile = MetadataProfilePeer::retrieveBySystemName($metadataElement['metadataProfile']); } if ($metadataProfile) { $metadata = MetadataPeer::retrieveByObject($metadataProfile->getId(), $objectType, $cuePoint->getId()); } } if (!$metadataProfile) { continue; } if (!$metadata) { $metadata = new Metadata(); $metadata->setPartnerId($partnerId); $metadata->setMetadataProfileId($metadataProfile->getId()); $metadata->setMetadataProfileVersion($metadataProfile->getVersion()); $metadata->setObjectType($objectType); $metadata->setObjectId($cuePoint->getId()); $metadata->setStatus(KalturaMetadataStatus::VALID); foreach ($metadataElement->children() as $metadataContent) { $xmlData = $metadataContent->asXML(); $errorMessage = ''; if (kMetadataManager::validateMetadata($metadataProfile->getId(), $xmlData, $errorMessage)) { $metadata->save(); $key = $metadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA); kFileSyncUtils::file_put_contents($key, $xmlData); kEventsManager::raiseEvent(new kObjectDataChangedEvent($metadata)); } break; } } } return $cuePoint; }
/** * @param Metadata $metadata * @param KalturaMetadataStatus $status * * returns metadata status */ protected static function setMetadataStatus(Metadata $metadata, $status, $metadataProfileVersion = null) { if ($metadataProfileVersion) { $metadata->setMetadataProfileVersion($metadataProfileVersion); } $metadata->setStatus($status); $metadata->save(); return $status; }
/** * Function returns metadata object which needs to be set with the new metadata XML * @param BaseObject $object * @param MetadataProfile $metadataProfileId */ protected static function createOrFindMetadataObject(BaseObject $object, MetadataProfile $metadataProfile) { $c = new Criteria(); $c->addAnd(MetadataPeer::PARTNER_ID, $object->getPartnerId(), Criteria::EQUAL); $c->addAnd(MetadataPeer::OBJECT_ID, $object->getId(), Criteria::EQUAL); $c->addAnd(MetadataPeer::METADATA_PROFILE_ID, $metadataProfile->getId(), Criteria::EQUAL); $c->addAnd(MetadataPeer::METADATA_PROFILE_VERSION, $metadataProfile->getVersion(), Criteria::EQUAL); $c->addAnd(MetadataPeer::OBJECT_TYPE, kMetadataManager::getTypeNameFromObject($object), Criteria::EQUAL); $c->addAnd(MetadataPeer::STATUS, Metadata::STATUS_VALID); $dbMetadata = MetadataPeer::doSelectOne($c); if (!$dbMetadata) { $dbMetadata = new Metadata(); $dbMetadata->setPartnerId($object->getPartnerId()); $dbMetadata->setMetadataProfileId($metadataProfile->getId()); $dbMetadata->setMetadataProfileVersion($metadataProfile->getVersion()); $dbMetadata->setObjectType(kMetadataManager::getTypeNameFromObject($object)); $dbMetadata->setObjectId($object->getId()); $dbMetadata->setStatus(Metadata::STATUS_VALID); $dbMetadata->save(); } else { $dbMetadata->incrementVersion(); $dbMetadata->save(); } return $dbMetadata; }
public function saveConfiguration($values) { // Restore database from backup? if ($values['template'] == 'backup') { if (!Curry_Backend_DatabaseHelper::restoreFromFile('db.txt')) { $this->addMessage('Unable to restore database content from db.txt', self::MSG_WARNING); } } // Create admin user if ($values['admin']['username']) { $access = array('*', 'Curry_Backend_Content/*'); $adminRole = self::createRole('Super', $access); $adminUser = self::createUser($values['admin']['username'], $values['admin']['password'], $adminRole); if ($adminUser->isNew()) { self::createFilebrowserAccess($adminRole, 'Root', ''); } $adminUser->save(); } // Create light user if ($values['user']['username']) { $access = array('Curry_Backend_FileBrowser', 'Curry_Backend_Page', 'Curry_Backend_Profile', 'Curry_Backend_Translations', 'Curry_Backend_Content/*'); $userRole = self::createRole('User', $access); $user = self::createUser($values['user']['username'], $values['user']['password'], $userRole); if ($user->isNew()) { $user->save(); self::createFilebrowserAccess($user, 'Home', 'user-content/' . $user->getUserId() . '/'); self::createFilebrowserAccess($userRole, 'Shared', 'content/'); } $user->save(); } if ($values['template'] != 'backup') { // Create default meta-data items $metadatas = array('Title' => 'text', 'Keywords' => 'textarea', 'Description' => 'textarea', 'Image' => 'previewImage'); foreach ($metadatas as $name => $type) { $metadata = new Metadata(); $metadata->setName($name); $metadata->setDisplayName($name); $metadata->setType($type); $metadata->save(); } $page = new Page(); $page->setName("Home"); $page->setURL("/"); $page->setVisible(true); $page->setEnabled(true); $page->makeRoot(); $page->save(); $page->createDefaultRevisions(); $page->save(); $pageRev = $page->getWorkingPageRevision(); $pageRev->setTemplate('Root.html'); $pageRev->save(); $pa = new PageAccess(); $pa->setPage($page); $pa->setPermSubpages(true); $pa->setPermVisible(true); $pa->setPermCreatePage(true); $pa->setPermCreateModule(true); $pa->setPermPublish(true); $pa->setPermProperties(true); $pa->setPermContent(true); $pa->setPermMeta(true); $pa->setPermModules(true); $pa->setPermRevisions(true); $pa->setPermPermissions(true); $pa->save(); } // Create template root $templateRoot = Curry_Core::$config->curry->template->root; if (!file_exists($templateRoot)) { @mkdir($templateRoot, 0777, true); } switch ($values['template']) { case 'empty': case 'curry': $source = Curry_Util::path(Curry_Core::$config->curry->wwwPath, 'shared', 'backend', 'common', 'templates', 'project-empty.html'); $templateFile = Curry_Util::path($templateRoot, 'Root.html'); if (!file_exists($templateFile)) { @copy($source, $templateFile); } break; case 'twitter-bootstrap': case 'html5boilerplate': } if (file_exists(Curry_Core::$config->curry->configPath)) { $config = new Zend_Config(require Curry_Core::$config->curry->configPath, true); $config->curry->name = $values['name']; $config->curry->adminEmail = $values['email']; if ($values['base_url']) { $config->curry->baseUrl = $values['base_url']; } else { unset($config->curry->baseUrl); } $config->curry->developmentMode = (bool) $values['development_mode']; $config->curry->secret = sha1(uniqid(mt_rand(), true) . microtime()); $writer = new Zend_Config_Writer_Array(); $writer->write(Curry_Core::$config->curry->configPath, $config); } return true; }
/** * Save metadata field. * * @param array $values */ public static function saveNewMetadata(array $values) { $metadata = new Metadata(); $metadata->setName($values['name']); $metadata->setDisplayName($values['display_name']); $metadata->setType($values['type']); $metadata->setDefaultValue($values['default_value']); $metadata->save(); }
public function saveConfiguration($values) { // Create admin role $access = array('*', 'Curry_Backend_Content/*'); $adminRole = self::createRole('Administrator', $access); if ($adminRole->isNew()) { self::createFilebrowserAccess($adminRole, 'Root', ''); } // Create editor role $access = array('Curry_Backend_FileBrowser', 'Curry_Backend_Page', 'Curry_Backend_Profile', 'Curry_Backend_Translations', 'Curry_Backend_Content/*'); $editorRole = self::createRole('Editor', $access); if ($editorRole->isNew()) { self::createFilebrowserAccess($editorRole, 'Shared', 'content/shared/'); } // Create admin user if ($values['admin']['username']) { $adminUser = self::createUser($values['admin']['username'], $values['admin']['password'], $adminRole); $adminUser->save(); } // Create default meta-data items $metadatas = array('Title' => 'text', 'Keywords' => 'textarea', 'Description' => 'textarea', 'Image' => 'previewImage'); foreach ($metadatas as $name => $type) { $metadata = new \Metadata(); $metadata->setName($name); $metadata->setDisplayName($name); $metadata->setType($type); $metadata->save(); } // Create pages $rootPage = new \Page(); $rootPage->setName("Root"); $rootPage->setURL("root/"); $rootPage->setVisible(true); $rootPage->setEnabled(true); $rootPage->makeRoot(); $rootPage->save(); $rootPage->createDefaultRevisions($rootPage); $rootPage->save(); $templatePage = new \Page(); $templatePage->setName('Templates'); $templatePage->setURL("templates/"); $templatePage->setIncludeInIndex(false); $templatePage->insertAsLastChildOf($rootPage); $templatePage->save(); $templatePage->createDefaultRevisions(); $pageRevision = $templatePage->getWorkingPageRevision(); $pageRevision->setTemplate('Root.html.twig'); $templatePage->save(); $homePage = new \Page(); $homePage->setName('Home'); $homePage->setURL("/"); $homePage->setVisible(true); $homePage->setEnabled(true); $homePage->insertAsLastChildOf($rootPage); $homePage->save(); $homePage->createDefaultRevisions($templatePage); $homePage->save(); // Create page access objects $pa = new \PageAccess(); $pa->setUserRole($adminRole); $pa->setPage($rootPage); $pa->setPermSubpages(true); $pa->setPermVisible(true); $pa->setPermCreatePage(true); $pa->setPermCreateModule(true); $pa->setPermPublish(true); $pa->setPermProperties(true); $pa->setPermContent(true); $pa->setPermMeta(true); $pa->setPermModules(true); $pa->setPermRevisions(true); $pa->setPermPermissions(true); $pa->save(); $pa = new \PageAccess(); $pa->setUserRole($editorRole); $pa->setPage($rootPage); $pa->setPermSubpages(true); $pa->setPermVisible(true); $pa->setPermCreatePage(true); $pa->setPermCreateModule(true); $pa->setPermPublish(true); $pa->setPermProperties(true); $pa->setPermContent(true); $pa->setPermMeta(true); $pa->setPermModules(true); $pa->setPermRevisions(true); $pa->setPermPermissions(false); $pa->save(); $pa = new \PageAccess(); $pa->setUserRole($editorRole); $pa->setPage($templatePage); $pa->setPermSubpages(true); $pa->setPermVisible(false); $pa->setPermCreatePage(false); $pa->setPermCreateModule(false); $pa->setPermPublish(false); $pa->setPermProperties(false); $pa->setPermContent(false); $pa->setPermMeta(false); $pa->setPermModules(false); $pa->setPermRevisions(false); $pa->setPermPermissions(false); $pa->save(); // Create template root $templateRoot = $this->app['template.root']; if (!file_exists($templateRoot)) { @mkdir($templateRoot, 0777, true); } if (file_exists($this->app['configPath'])) { $config = $this->app->openConfiguration(); $config->name = $values['name']; $config->adminEmail = $values['email']; if (!isset($config->backend)) { $config->backend = array(); } $config->backend->templatePage = $templatePage->getPageId(); if ($values['base_url']) { $config->baseUrl = $values['base_url']; } else { unset($config->baseUrl); } $config->developmentMode = (bool) $values['development_mode']; $config->secret = sha1(uniqid(mt_rand(), true) . microtime()); $this->app->writeConfiguration($config); } return true; }