/**
  * Test the addition of a mediaEntry with proeprty "categories" set.
  * @param string $categories
  * @dataProvider provideData
  */
 public function testAddWithCategories($categories)
 {
     $mediaEntry = new KalturaMediaEntry();
     $mediaEntry->name = uniqid();
     $mediaEntry->mediaType = KalturaMediaType::VIDEO;
     $mediaEntry->categories = $categories;
     $mediaEntry = $this->client->media->add($mediaEntry);
     var_dump(KAutoloader::getClassFilePath(get_class($this->client)));
     $categoryNames = explode(",", $categories);
     foreach ($categoryNames as $categoryName) {
         $filter = new KalturaCategoryFilter();
         $filter->fullNameEqual = $categoryName;
         $results = $this->client->category->listAction($filter);
         $this->assertEquals(1, $results->totalCount, "Unexpected number of categories with fullname {$categoryName}.");
         $catId = $results->objects[0]->id;
         // Assert that the entry's "categoriesIds" property was updated properly.
         $entryCatIds = explode(',', $mediaEntry->categoriesIds);
         $this->assertTrue(in_array($catId, $entryCatIds), "Entry's categoriesIds property should containt category Id [{$catId}] for category [{$categoryName}]");
         //Assert that a KalturaCategoryEntry object was created for the entry and each category it was associated with.
         $catEntryFilter = new KalturaCategoryEntryFilter();
         $catEntryFilter->categoryIdEqual = $catId;
         $catEntryFilter->entryIdEqual = $mediaEntry->id;
         try {
             $res = $this->client->categoryEntry->listAction($catEntryFilter);
             $this->assertGreaterThan(0, $res->totalCount > 0);
         } catch (Exception $e) {
             $this->assertEquals(0, 1, "Unexpected exception thrown - expected categoryEntry object for entry Id" . $mediaEntry->id . " and category Id {$catId}");
         }
     }
 }
 /**
  * @param string $type
  * @return KalturaTypeReflector
  */
 static function get($type)
 {
     if (!self::$_enabled) {
         return new KalturaTypeReflector($type);
     }
     if (!array_key_exists($type, self::$_loadedTypeReflectors)) {
         $cachedDir = KAutoloader::buildPath(kConf::get("cache_root_path"), "api_v3", "typeReflector");
         if (!is_dir($cachedDir)) {
             mkdir($cachedDir);
             chmod($cachedDir, 0755);
         }
         $cachedFilePath = $cachedDir . DIRECTORY_SEPARATOR . $type . ".cache";
         $typeReflector = null;
         if (file_exists($cachedFilePath)) {
             $cachedData = file_get_contents($cachedFilePath);
             $typeReflector = unserialize($cachedData);
         }
         if (!$typeReflector) {
             $typeReflector = new KalturaTypeReflector($type);
             $cachedData = serialize($typeReflector);
             $bytesWritten = kFile::safeFilePutContents($cachedFilePath, $cachedData);
             if (!$bytesWritten) {
                 $folderPermission = substr(decoct(fileperms(dirname($cachedFilePath))), 2);
                 error_log("Kaltura type reflector could not be saved to path [{$cachedFilePath}] type [{$type}] folder permisisons [{$folderPermission}]");
             }
         }
         self::$_loadedTypeReflectors[$type] = $typeReflector;
     }
     return self::$_loadedTypeReflectors[$type];
 }
 /**
  * 
  * Creates a new Kaltura test Object
  * @param string $name
  * @param array $data
  * @param string $dataName
  */
 public function __construct($name = null, array $data = array(), $dataName = '')
 {
     parent::__construct($name, $data, $dataName);
     $class = get_class($this);
     if ($name) {
         KalturaLog::info("_____________________________________ [{$class}] [{$name}] ___________________________________");
     } else {
         KalturaLog::info("__________________________________________ [{$class}] ______________________________________");
     }
     $testFilePath = KAutoloader::getClassFilePath($class);
     $this->testFolder = dirname($testFilePath);
     $this->inputs = $data;
     KalturaLog::info("Loads config file [{$testFilePath}.ini]");
     $this->config = new KalturaTestConfig("{$testFilePath}.ini");
     $testConfig = $this->config->get('config');
     if (!$testConfig) {
         $testConfig = new Zend_Config(array('source' => KalturaTestSource::XML), true);
         $this->config->config = $testConfig;
         $this->config->saveToIniFile();
     }
     $this->dataSource = $testConfig->source;
     $this->outputFolder = $testConfig->outputFolder;
     if ($this->outputFolder && !is_dir($this->outputFolder)) {
         KalturaLog::info("Creating folder output [{$this->outputFolder}]");
         mkdir($this->outputFolder, 777, true);
     }
 }
示例#4
0
 static function cacheMap($servicePath, $cacheFilePath)
 {
     if (!is_dir($servicePath)) {
         throw new Exception('Invalid directory [' . $servicePath . ']');
     }
     $servicePath = realpath($servicePath);
     $serviceMap = array();
     $classMap = KAutoloader::getClassMap();
     $checkedClasses = array();
     foreach ($classMap as $class => $classFilePath) {
         $classFilePath = realpath($classFilePath);
         if (strpos($classFilePath, $servicePath) === 0) {
             $reflectionClass = new ReflectionClass($class);
             if ($reflectionClass->isSubclassOf('KalturaBaseService')) {
                 $docComment = $reflectionClass->getDocComment();
                 $parser = new KalturaDocCommentParser($docComment);
                 $serviceId = strtolower($parser->serviceName);
                 $serviceMap[$serviceId] = $class;
             }
         }
         $checkedClasses[] = $class;
     }
     $pluginServices = array();
     $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaServices');
     foreach ($pluginInstances as $pluginName => $pluginInstance) {
         $pluginServices = $pluginInstance->getServicesMap();
         foreach ($pluginServices as $serviceName => $serviceClass) {
             $serviceName = strtolower($serviceName);
             $serviceId = "{$pluginName}_{$serviceName}";
             $pluginServices[$serviceId] = $serviceClass;
             $serviceMap[$serviceId] = $serviceClass;
         }
     }
     $cachedFile = '';
     $cachedFile .= '<?php' . PHP_EOL;
     $cachedFile .= 'self::$services = ' . var_export($serviceMap, true) . ';' . PHP_EOL;
     if (!is_dir(dirname($cacheFilePath))) {
         mkdir(dirname($cacheFilePath), 0777);
     }
     file_put_contents($cacheFilePath, $cachedFile);
 }
 /**
  * @param string $type
  * @return KalturaTypeReflector
  */
 static function get($type)
 {
     if (!self::$_enabled) {
         return new KalturaTypeReflector($type);
     }
     if (!array_key_exists($type, self::$_loadedTypeReflectors)) {
         $cachedDir = KAutoloader::buildPath(kConf::get("cache_root_path"), "api_v3", "typeReflector");
         if (!is_dir($cachedDir)) {
             mkdir($cachedDir);
         }
         $cachedFilePath = $cachedDir . DIRECTORY_SEPARATOR . $type . ".cache";
         if (file_exists($cachedFilePath)) {
             $cachedData = file_get_contents($cachedFilePath);
             $typeReflector = unserialize($cachedData);
         } else {
             $typeReflector = new KalturaTypeReflector($type);
             $cachedData = serialize($typeReflector);
             file_put_contents($cachedFilePath, $cachedData);
         }
         self::$_loadedTypeReflectors[$type] = $typeReflector;
     }
     return self::$_loadedTypeReflectors[$type];
 }
 /**
  * Load and cache the class map
  */
 private static function loadClassMap()
 {
     if (!self::$_classMapFileLocation || !file_exists(self::$_classMapFileLocation) || self::$_noCache == true) {
         // cached map doesn't exists, rebuild the cache map
         foreach (self::$_classPath as $dir) {
             if (strpos($dir, DIRECTORY_SEPARATOR . "*") == strlen($dir) - 2) {
                 $dir = substr($dir, 0, strlen($dir) - 2);
                 $recursive = true;
             } else {
                 $recursive = false;
             }
             self::scanDirectory($dir, $recursive);
         }
         if (self::$_noCache === false && self::$_classMapFileLocation) {
             // save the cached map
             $bytesWritten = file_put_contents(self::$_classMapFileLocation, serialize(self::$_classMap));
             if (!$bytesWritten) {
                 $folderPermission = substr(decoct(fileperms(dirname(self::$_classMapFileLocation))), 2);
                 error_log("PHP Class map could not be saved to path [" . self::$_classMapFileLocation . "] folder permisisons [{$folderPermission}]");
                 die("PHP Class map could not be saved");
             }
         }
     } else {
         if (count(self::$_classMap) == 0) {
             // if cached map was not loaded but exists on the disk, load it
             self::$_classMap = unserialize(file_get_contents(self::$_classMapFileLocation));
             if (!is_array(self::$_classMap)) {
                 $permission = substr(decoct(fileperms(self::$_classMapFileLocation)), 2);
                 error_log("PHP Class map could not be loaded from path [" . self::$_classMapFileLocation . "] file permisisons [{$permission}]");
                 die('PHP Class map could not be loaded');
             }
         }
     }
 }
示例#7
0
<?php

// AWS SDK PHP Client Library
require_once KAutoloader::buildPath(KALTURA_ROOT_PATH, 'vendor', 'aws', 'aws-autoloader.php');
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
use Aws\S3\Enum\CannedAcl;
/**
 * Extends the 'kFileTransferMgr' class & implements a file transfer manager using the Amazon S3 protocol with Authentication Version 4.
 * For additional comments please look at the 'kFileTransferMgr' class.
 *
 * @package infra
 * @subpackage Storage
 */
class s3Mgr extends kFileTransferMgr
{
    private $s3;
    protected $filesAcl = CannedAcl::PRIVATE_ACCESS;
    protected $s3Region = '';
    // instances of this class should be created usign the 'getInstance' of the 'kFileTransferMgr' class
    protected function __construct(array $options = null)
    {
        parent::__construct($options);
        if ($options && isset($options['filesAcl'])) {
            $this->filesAcl = $options['filesAcl'];
        }
        if ($options && isset($options['s3Region'])) {
            $this->s3Region = $options['s3Region'];
        }
        // do nothing
        $this->connection_id = 1;
示例#8
0
文件: index.php 项目: DBezemer/server
<?php

require_once __DIR__ . "/../../bootstrap.php";
KalturaLog::setContext("CLIENTS");
KalturaLog::debug(__FILE__ . " start");
$generatorPath = KAutoloader::buildPath(KALTURA_ROOT_PATH, "generator");
$generatorOutputPath = KAutoloader::buildPath(KALTURA_ROOT_PATH, "generator", "output");
$generatorConfigPath = KAutoloader::buildPath(KALTURA_ROOT_PATH, "generator", "config.ini");
$config = new Zend_Config_Ini($generatorConfigPath);
?>
<ul>
<?php 
foreach ($config as $name => $item) {
    if (!$item->get("public-download")) {
        continue;
    }
    $outputFilePath = KAutoloader::buildPath($generatorOutputPath, $name . ".tar.gz");
    $outputFileRealPath = realpath($outputFilePath);
    if ($outputFileRealPath) {
        print '<li>';
        print '<a href="download.php?name=' . $name . '"> Download ' . $name . '</a>';
        print '</li>';
    }
}
?>
</ul>
<?php 
KalturaLog::debug(__FILE__ . " end");
* limitations under the License.
*
* Modified by Akvelon Inc.
* 2014-06-30
* http://www.akvelon.com/contact-us
*/
/**
 * 
 * @package Scheduler
 */
require_once "../infra/bootstrap_base.php";
require_once KALTURA_ROOT_PATH . '/infra/kConf.php';
require_once KALTURA_ROOT_PATH . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
define("KALTURA_BATCH_PATH", KALTURA_ROOT_PATH . "/batch");
// Autoloader - override the autoloader defaults
require_once KALTURA_INFRA_PATH . "/KAutoloader.php";
KAutoloader::setClassPath(array(KAutoloader::buildPath(KALTURA_ROOT_PATH, "infra", "*"), KAutoloader::buildPath(KALTURA_ROOT_PATH, "vendor", "PHPMailer", "*"), KAutoloader::buildPath(KALTURA_ROOT_PATH, "vendor", "phpseclib", "*"), KAutoloader::buildPath(KALTURA_ROOT_PATH, "plugins", "*"), KAutoloader::buildPath(KALTURA_ROOT_PATH, "vendor", "propel", "*"), KAutoloader::buildPath(KALTURA_ROOT_PATH, "alpha", "*"), KAutoloader::buildPath(KALTURA_BATCH_PATH, "*")));
KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "plugins", "*", "batch", "*"));
KAutoloader::setIncludePath(array(KAutoloader::buildPath(KALTURA_ROOT_PATH, "vendor", "ZendFramework", "library")));
KAutoloader::setClassMapFilePath(kConf::get("cache_root_path") . '/batch/classMap.cache');
KAutoloader::register();
set_include_path(get_include_path() . PATH_SEPARATOR . KAutoloader::buildPath(KALTURA_ROOT_PATH, "vendor", "phpseclib"));
set_include_path(get_include_path() . PATH_SEPARATOR . KAutoloader::buildPath(KALTURA_ROOT_PATH, "alpha", "apps", "kaltura", "lib"));
// Logger
$loggerConfigPath = KALTURA_ROOT_PATH . "/configurations/logger.ini";
try {
    $config = new Zend_Config_Ini($loggerConfigPath);
    KalturaLog::initLog($config->batch);
    KalturaLog::setContext("BATCH");
} catch (Zend_Config_Exception $ex) {
}
示例#10
0
 /**
  * Load and cache the class map
  */
 private static function loadClassMap()
 {
     if (!file_exists(self::$_classMapFileLocation) || self::$_noCache == true) {
         // cached map doesn't exists, rebuild the cache map
         foreach (self::$_classPath as $dir) {
             if (strpos($dir, DIRECTORY_SEPARATOR . "*") == strlen($dir) - 2) {
                 $dir = substr($dir, 0, strlen($dir) - 2);
                 $recursive = true;
             } else {
                 $recursive = false;
             }
             self::scanDirectory($dir, $recursive);
         }
         if (self::$_noCache === false) {
             // save the cached map
             file_put_contents(self::$_classMapFileLocation, serialize(self::$_classMap));
         }
     } else {
         if (count(self::$_classMap) == 0) {
             // if cached map was not loaded but exists on the disk, load it
             self::$_classMap = unserialize(file_get_contents(self::$_classMapFileLocation));
         }
     }
 }
<?php

require_once ".." . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "bootstrap.php";
KalturaLog::setContext("CLIENTS");
KalturaLog::debug(__FILE__ . " start");
$requestedName = isset($_GET["name"]) ? $_GET['name'] : null;
if (!$requestedName) {
    die("File not found");
}
$generatorOutputPath = KAutoloader::buildPath(KALTURA_ROOT_PATH, "generator", "output");
$generatorConfigPath = KAutoloader::buildPath(KALTURA_ROOT_PATH, "generator", "config.ini");
$config = new Zend_Config_Ini($generatorConfigPath);
foreach ($config as $name => $item) {
    if ($name === $requestedName && $item->get("public-download")) {
        $fileName = $name . ".tar.gz";
        $outputFilePath = KAutoloader::buildPath($generatorOutputPath, $fileName);
        $outputFilePath = realpath($outputFilePath);
        header("Content-disposition: attachment; filename={$fileName}");
        kFile::dumpFile($outputFilePath, "application/gzip");
        die;
    }
}
die("File not found");
KalturaLog::debug(__FILE__ . " end");
 /**
  * 
  * Used to initialize the ui conf deployment like a bootstarp fiel
  * @param unknown_type $conf_file_path
  */
 public static function init($conf_file_path)
 {
     require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "infra" . DIRECTORY_SEPARATOR . "bootstrap_base.php";
     require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "infra" . DIRECTORY_SEPARATOR . "kConf.php";
     define("KALTURA_API_PATH", KALTURA_ROOT_PATH . DIRECTORY_SEPARATOR . "api_v3");
     // Autoloader
     require_once KALTURA_INFRA_PATH . DIRECTORY_SEPARATOR . "KAutoloader.php";
     KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "vendor", "propel", "*"));
     KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_API_PATH, "lib", "*"));
     KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_API_PATH, "services", "*"));
     KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "alpha", "plugins", "*"));
     // needed for testmeDoc
     KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "plugins", "*"));
     KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "generator"));
     // needed for testmeDoc
     KAutoloader::setClassMapFilePath(kConf::get("cache_root_path") . '/deploy/' . basename(__FILE__) . '.cache');
     //KAutoloader::dumpExtra();
     KAutoloader::register();
     $dbConf = kConf::getDB();
     DbManager::setConfig($dbConf);
     DbManager::initialize();
     date_default_timezone_set(kConf::get("date_default_timezone"));
     //		try
     //		{
     $confObj = new Zend_Config_Ini($conf_file_path);
     //		}
     //		catch(Exception $ex)
     //		{
     //			echo 'Exiting on ERROR: '.$ex->getMessage().PHP_EOL;
     //			exit(1);
     //		}
     return $confObj;
 }
示例#13
0
 public static function init($conf_file_path)
 {
     require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "infra" . DIRECTORY_SEPARATOR . "bootstrap_base.php";
     require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'kConf.php';
     define("KALTURA_API_PATH", KALTURA_ROOT_PATH . DIRECTORY_SEPARATOR . "api_v3");
     // Autoloader
     require_once KALTURA_INFRA_PATH . DIRECTORY_SEPARATOR . "KAutoloader.php";
     KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "vendor", "propel", "*"));
     KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_API_PATH, "lib", "*"));
     KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_API_PATH, "services", "*"));
     KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "alpha", "plugins", "*"));
     // needed for testmeDoc
     KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "plugins", "*"));
     KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "generator"));
     // needed for testmeDoc
     KAutoloader::setClassMapFilePath(kConf::get("cache_root_path") . '/deploy/classMap.cache');
     //KAutoloader::dumpExtra();
     KAutoloader::register();
     $dbConf = kConf::getDB();
     DbManager::setConfig($dbConf);
     DbManager::initialize();
     $conf = parse_ini_file($conf_file_path, true);
     $confObj = new Zend_Config_Ini($conf_file_path);
     return $confObj;
 }
 protected function initClassMap()
 {
     if ($this->_classMap !== null) {
         return;
     }
     $classMapFileLocation = KAutoloader::getClassMapFilePath();
     $this->_classMap = unserialize(file_get_contents($classMapFileLocation));
 }
示例#15
0
 private function loadChildTypes(KalturaTypeReflector $typeReflector)
 {
     $typesDir = KALTURA_ROOT_PATH . DIRECTORY_SEPARATOR . "api_v3" . DIRECTORY_SEPARATOR . "lib" . DIRECTORY_SEPARATOR . "types" . DIRECTORY_SEPARATOR;
     $typesDir = realpath($typesDir);
     $classMapFileLcoation = KAutoloader::getClassMapFilePath();
     $classMap = unserialize(file_get_contents($classMapFileLcoation));
     foreach ($classMap as $class => $path) {
         if (strpos($path, $typesDir) === 0) {
             $reflector = new ReflectionClass($class);
             if ($class == 'KalturaFileSyncFilter') {
                 continue;
             }
             if ($reflector->isSubclassOf($typeReflector->getType())) {
                 $classTypeReflector = KalturaTypeReflectorCacher::get($class);
                 if ($classTypeReflector) {
                     $this->loadTypesRecursive($classTypeReflector);
                 }
             }
         }
     }
 }
<?php

require_once "../../bootstrap.php";
KalturaLog::setContext("TESTME");
$type = $_GET["type"];
$bench_start = microtime(true);
KalturaLog::INFO(">------- api_v3 testme type [{$type}]-------");
function toArrayRecursive(KalturaPropertyInfo $propInfo)
{
    return $propInfo->toArray(true);
}
$subClasses = array();
try {
    KalturaTypeReflector::setClassInheritMapPath(KAutoloader::buildPath(kConf::get("cache_root_path"), "api_v3", "KalturaClassInheritMap.cache"));
    if (!KalturaTypeReflector::hasClassInheritMapCache()) {
        $config = new Zend_Config_Ini("../../config/testme.ini");
        $indexConfig = $config->get('testme');
        $include = $indexConfig->get("include");
        $exclude = $indexConfig->get("exclude");
        $excludePaths = $indexConfig->get("excludepaths");
        $additional = $indexConfig->get("additional");
        $clientGenerator = new DummyForDocsClientGenerator();
        $clientGenerator->setIncludeOrExcludeList($include, $exclude, $excludePaths);
        $clientGenerator->setAdditionalList($additional);
        $clientGenerator->load();
        $objects = $clientGenerator->getTypes();
        KalturaTypeReflector::setClassMap(array_keys($objects));
    }
    $subClassesNames = KalturaTypeReflector::getSubClasses($type);
    foreach ($subClassesNames as $subClassName) {
        $subClass = new KalturaPropertyInfo($subClassName);
 private function getClassFilePath($class)
 {
     $map = KAutoloader::getClassMap();
     if (!isset($map[$class])) {
         throw new Exception("File path was not found for [{$class}]");
     }
     return $map[$class];
 }
示例#18
0
function init($conf_file_path, $infra_path)
{
    $conf = parse_ini_file($conf_file_path, true);
    require_once KALTURA_ROOT_PATH . DIRECTORY_SEPARATOR . "infra" . DIRECTORY_SEPARATOR . "KAutoloader.php";
    KAutoloader::setIncludePath(array(KAutoloader::buildPath(KALTURA_ROOT_PATH, "vendor", "ZendFramework", "library")));
    KAutoloader::register();
    $confObj = new Zend_Config_Ini($conf_file_path);
    return $confObj;
}
示例#19
0
 protected function writeAfterService(KalturaServiceReflector $serviceReflector)
 {
     $this->writeTest("\t/**");
     $this->writeTest("\t * Called when all tests are done");
     $this->writeTest("\t * @param int \$id");
     $this->writeTest("\t * @return int");
     $this->writeTest("\t * @depends {$this->lastDependencyTest} - TODO: replace {$this->lastDependencyTest} with last test function that uses that id");
     $this->writeTest("\t */");
     $this->writeTest("\tpublic function testFinished(\$id)");
     $this->writeTest("\t{");
     $this->writeTest("\t\treturn \$id;");
     $this->writeTest("\t}");
     $this->writeTest("");
     $this->writeTest("}");
     $this->writeBase("\t/**");
     $this->writeBase("\t * Called when all tests are done");
     $this->writeBase("\t * @param int \$id");
     $this->writeBase("\t * @return int");
     $this->writeBase("\t */");
     $this->writeBase("\tabstract public function testFinished(\$id);");
     $this->writeBase("");
     $this->writeBase("}");
     $serviceName = $serviceReflector->getServiceName();
     $serviceClass = $serviceReflector->getServiceClass();
     $testPath = realpath(dirname(__FILE__) . '/../') . "/tests/api/{$serviceName}";
     if ($serviceReflector->isFromPlugin()) {
         $servicePath = KAutoloader::getClassFilePath($serviceClass);
         $testPath = realpath(dirname($servicePath) . '/../') . "/tests/services/{$serviceName}";
     }
     $this->writeToFile("{$testPath}/{$serviceClass}BaseTest.php", $this->_txtBase);
     $this->writeToFile("{$testPath}/{$serviceClass}Test.php", $this->_txtTest, false);
     $this->writeToFile("{$testPath}/{$serviceClass}Test.php.ini", $this->_txtIni, false);
 }
示例#20
0
 public function autoload($class)
 {
     KAutoloader::autoload($class);
 }
示例#21
0
 private function writeOrderByEnumForType(KalturaTypeReflector $type)
 {
     $map = KAutoloader::getClassMap();
     if (!isset($map[$type->getType()])) {
         return;
     }
     $this->_txt = "";
     $parentType = $type;
     while (1) {
         $parentType = $parentType->getParentTypeReflector();
         if ($parentType === null || $parentType->isFilterable()) {
             break;
         }
     }
     $partnetClassName = $parentType ? $parentType->getType() . "OrderBy" : "KalturaStringEnum";
     $enumName = $type->getType() . "OrderBy";
     $enumPath = dirname($map[$type->getType()]) . "/filters/orderEnums/{$enumName}.php";
     $subpackage = ($type->getPackage() == 'api' ? '' : 'api.') . 'filters.enum';
     $this->appendLine("<?php");
     $this->appendLine("/**");
     $this->appendLine(" * @package " . $type->getPackage());
     $this->appendLine(" * @subpackage {$subpackage}");
     $this->appendLine(" */");
     $this->appendLine("class {$enumName} extends {$partnetClassName}");
     $this->appendLine("{");
     foreach ($type->getCurrentProperties() as $prop) {
         $filters = $prop->getFilters();
         foreach ($filters as $filter) {
             if ($filter == "order") {
                 $this->appendLine("\tconst " . $this->getOrderByConst($prop->getName()) . "_ASC = \"+" . $prop->getName() . "\";");
                 $this->appendLine("\tconst " . $this->getOrderByConst($prop->getName()) . "_DESC = \"-" . $prop->getName() . "\";");
             }
         }
     }
     $reflectionClass = new ReflectionClass($type->getType());
     if (!$type->isAbstract() && $reflectionClass->getMethod("getExtraFilters")->getDeclaringClass()->getName() === $reflectionClass->getName()) {
         $extraFilters = $type->getInstance()->getExtraFilters();
         if ($extraFilters) {
             foreach ($extraFilters as $filterFields) {
                 if (!isset($filterFields["order"])) {
                     continue;
                 }
                 $fieldName = $filterFields["order"];
                 $fieldConst = $this->getOrderByConst($fieldName);
                 $this->appendLine("\tconst {$fieldConst}_ASC = \"+{$fieldName}\";");
                 $this->appendLine("\tconst {$fieldConst}_DESC = \"-{$fieldName}\";");
             }
         }
     }
     $this->appendLine("}");
     $this->writeToFile($enumPath, $this->_txt);
 }
示例#22
0
 protected function initClassMap()
 {
     if ($this->_classMap !== null) {
         return;
     }
     $this->_classMap = KAutoloader::getClassMap();
 }
 /**
  * 
  * Inits the global data file
  * @return true - If global exists or was created, null other wise 
  */
 private static function initDataFile()
 {
     if (is_null(KalturaGlobalData::$dataFilePath)) {
         $classFilePath = KAutoloader::getClassFilePath("KalturaGlobalData");
         $dir = dirname($classFilePath);
         KalturaGlobalData::setDataFilePath($dir . "/" . KalturaGlobalData::DEFAULT_DATA_PATH);
     }
     if (file_exists(KalturaGlobalData::$dataFilePath)) {
         KalturaGlobalData::$dataFile = new KalturaTestConfig(KalturaGlobalData::$dataFilePath);
     } else {
         print "Global file no found at: " . KalturaGlobalData::$dataFilePath . "\n";
         return null;
     }
     return true;
 }
示例#24
0
function init($conf_file_path)
{
    $conf = parse_ini_file($conf_file_path, true);
    require_once $conf['statics']['infra_path'] . DIRECTORY_SEPARATOR . "bootstrap_base.php";
    require_once KALTURA_INFRA_PATH . DIRECTORY_SEPARATOR . "KAutoloader.php";
    KAutoloader::setIncludePath(array(KAutoloader::buildPath(KALTURA_ROOT_PATH, "vendor", "ZendFramework", "library")));
    KAutoloader::register();
    $confObj = new Zend_Config_Ini('config.ini');
    return $confObj;
}
示例#25
0
 public static function loadClassMapFromCache()
 {
     if (self::$_classMap) {
         return true;
     }
     if (!file_exists(self::$_classMapFileLocation)) {
         return false;
     }
     // if cached map was not loaded but exists on the disk, load it
     self::$_classMap = unserialize(file_get_contents(self::$_classMapFileLocation));
     if (!is_array(self::$_classMap)) {
         $permission = substr(decoct(fileperms(self::$_classMapFileLocation)), 2);
         error_log("PHP Class map could not be loaded from path [" . self::$_classMapFileLocation . "] file permissions [{$permission}]");
         die('PHP Class map could not be loaded');
     }
     return true;
 }
 /**
  * 
  * The test data provider (gets the data for the different tests)
  * @param string $className - The class name
  * @param string $procedureName - The current method (test) name
  * @return array<array>();
  */
 public function provider($className, $procedureName)
 {
     //print("In provider for $className, $procedureName \n");
     //Gets from the given class the class data file
     $class = get_class($this);
     $classFilePath = KAutoloader::getClassFilePath($class);
     $testClassDir = dirname($classFilePath);
     $dataFilePath = $testClassDir . DIRECTORY_SEPARATOR . "testsData/{$className}.data";
     KalturaLog::debug("The data file path [" . $dataFilePath . "]");
     if (file_exists($dataFilePath)) {
         $simpleXML = kXml::openXmlFile($dataFilePath);
     } else {
         //TODO: Give notice or create the file don't throw an exception
         throw new Exception("Data file [{$dataFilePath}] not found");
     }
     $inputsForTestProcedure = array();
     foreach ($simpleXML->TestProcedureData as $xmlTestProcedureData) {
         if ($xmlTestProcedureData["testProcedureName"] != $procedureName) {
             continue;
         }
         foreach ($xmlTestProcedureData->TestCaseData as $xmlTestCaseData) {
             $testCaseInstanceInputs = array();
             foreach ($xmlTestCaseData->Input as $input) {
                 $object = KalturaTestDataObject::generatefromXml($input);
                 //Add the new input to the test case instance data
                 $testCaseInstanceInputs[] = $object;
             }
             foreach ($xmlTestCaseData->OutputReference as $output) {
                 $object = KalturaTestDataObject::generatefromXml($output);
                 //Add the new output reference to the test case instance data
                 $testCaseInstanceInputs[] = $object;
             }
             //Add the test case into the test procedure data
             $inputsForTestProcedure[] = $testCaseInstanceInputs;
         }
     }
     KalturaLog::info("Tests data provided Before transformation to objects: \n[" . print_r($inputsForTestProcedure, true) . "]");
     $inputsForTestProcedure = $this->transformToObjects($inputsForTestProcedure);
     KalturaLog::info("Tests data provided [" . print_r($inputsForTestProcedure, true) . "]");
     return $inputsForTestProcedure;
 }
 static function cacheMap($servicePath, $cacheFilePath)
 {
     if (!is_dir($servicePath)) {
         throw new Exception('Invalid directory [' . $servicePath . ']');
     }
     $servicePath = realpath($servicePath);
     $serviceMap = array();
     $classMap = KAutoloader::getClassMap();
     $checkedClasses = array();
     //Retrieve all service classes from the classMap.
     $serviceClasses = array();
     foreach ($classMap as $class => $classFilePath) {
         $classFilePath = realpath($classFilePath);
         if (strpos($classFilePath, $servicePath) === 0) {
             $reflectionClass = new ReflectionClass($class);
             if ($reflectionClass->isSubclassOf('KalturaBaseService')) {
                 $serviceDoccomment = new KalturaDocCommentParser($reflectionClass->getDocComment());
                 $serviceClasses[$serviceDoccomment->serviceName] = $class;
             }
         }
     }
     //Retrieve all plugin service classes.
     $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaServices');
     foreach ($pluginInstances as $pluginName => $pluginInstance) {
         $pluginServices = $pluginInstance->getServicesMap();
         foreach ($pluginServices as $serviceName => $serviceClass) {
             $serviceName = strtolower($serviceName);
             $serviceId = "{$pluginName}_{$serviceName}";
             $serviceClasses[$serviceId] = $serviceClass;
         }
     }
     //Add core & plugin services to the services map
     $aliasActions = array();
     foreach ($serviceClasses as $serviceId => $serviceClass) {
         $serviceReflectionClass = KalturaServiceReflector::constructFromClassName($serviceClass);
         $serviceMapEntry = new KalturaServiceActionItem();
         $serviceMapEntry->serviceId = $serviceId;
         $serviceMapEntry->serviceClass = $serviceClass;
         $serviceMapEntry->serviceInfo = $serviceReflectionClass->getServiceInfo();
         $actionMap = array();
         $nativeActions = $serviceReflectionClass->getActions();
         foreach ($nativeActions as $actionId => $actionName) {
             $actionMap[strtolower($actionId)] = array("serviceClass" => $serviceClass, "actionMethodName" => $actionName, "serviceId" => $serviceId, "actionName" => $actionId);
         }
         $serviceMapEntry->actionMap = $actionMap;
         $serviceMap[strtolower($serviceId)] = $serviceMapEntry;
         foreach ($serviceReflectionClass->getAliasActions() as $alias => $methodName) {
             $aliasActions[$alias] = "{$serviceId}.{$methodName}";
         }
     }
     // add aliases
     foreach ($aliasActions as $aliasAction => $sourceAction) {
         list($aliasService, $aliasAction) = explode('.', $aliasAction);
         list($sourceService, $sourceAction) = explode('.', $sourceAction);
         $aliasService = strtolower($aliasService);
         $sourceService = strtolower($sourceService);
         $extServiceClass = $serviceClasses[$sourceService];
         $serviceMap[$aliasService]->actionMap[strtolower($aliasAction)] = array("serviceClass" => $extServiceClass, "actionMethodName" => $sourceAction, "serviceId" => $sourceService, "actionName" => $aliasAction);
     }
     // filter out services that have no actions
     $serviceMap = array_filter($serviceMap, array('KalturaServicesMap', 'filterEmptyServices'));
     if (!is_dir(dirname($cacheFilePath))) {
         mkdir(dirname($cacheFilePath));
         chmod(dirname($cacheFilePath), 0755);
     }
     kFile::safeFilePutContents($cacheFilePath, serialize($serviceMap), 0644);
 }
示例#28
0
<?php

/**
 * 
 * @package Scheduler
 */
chdir(__DIR__);
define('KALTURA_ROOT_PATH', realpath(__DIR__ . '/../'));
require_once KALTURA_ROOT_PATH . '/alpha/config/kConf.php';
define("KALTURA_BATCH_PATH", KALTURA_ROOT_PATH . "/batch");
// Autoloader - override the autoloader defaults
require_once KALTURA_ROOT_PATH . "/infra/KAutoloader.php";
KAutoloader::setClassPath(array(KAutoloader::buildPath(KALTURA_ROOT_PATH, "infra", "*"), KAutoloader::buildPath(KALTURA_ROOT_PATH, "vendor", "*"), KAutoloader::buildPath(KALTURA_ROOT_PATH, "plugins", "*"), KAutoloader::buildPath(KALTURA_BATCH_PATH, "*")));
KAutoloader::addClassPath(KAutoloader::buildPath(KALTURA_ROOT_PATH, "plugins", "*", "batch", "*"));
KAutoloader::setIncludePath(array(KAutoloader::buildPath(KALTURA_ROOT_PATH, "vendor", "ZendFramework", "library")));
KAutoloader::setClassMapFilePath(kEnvironment::get("cache_root_path") . '/batch/classMap.cache');
KAutoloader::register();
// Logger
$loggerConfigPath = KALTURA_ROOT_PATH . "/configurations/logger.ini";
try {
    $config = new Zend_Config_Ini($loggerConfigPath);
    KalturaLog::initLog($config->batch_scheduler);
    KalturaLog::setContext("BATCH");
} catch (Zend_Config_Exception $ex) {
}
 public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
 {
     //		print("In startTestSuite - for suite = {$suite->getName()}\n");
     KalturaLog::debug("In startTestSuite - for suite = {$suite->getName()}");
     if ($suite instanceof PHPUnit_Framework_TestSuite_DataProvider) {
         //Get the test procedure name from the suite name which is (testCase::testProcedure)
         $testNames = explode("::", $suite->getName());
         $testName = $testNames[0];
         if (isset($testNames[1])) {
             $testName = $testNames[1];
         }
         $testCase = $testNames[0];
         if (is_null(KalturaTestListener::$testCaseFailures)) {
             KalturaLog::debug("KalturaTestCaseFailures is null creating empty test case failures for {$testCase}\n");
             KalturaTestListener::$testCaseFailures = new KalturaTestCaseFailures($testName);
         }
         $testProcedure = KalturaTestListener::$testCaseFailures->getTestProcedureFailure($testName);
         //if the test procedure exists
         if (!$testProcedure) {
             KalturaTestListener::$testCaseFailures->addTestProcedureFailure(new KalturaTestProcedureFailure($testName));
         } else {
             KalturaLog::alert("Test procedure [{$testName}] already added");
         }
     } else {
         //Check if the test belongs to the same test case failures (by the first test of the suite)
         $test = $suite->testAt(0);
         if ($test instanceof PHPUnit_Framework_TestSuite_DataProvider) {
             $test = $test->testAt(0);
         }
         $class = get_class($test);
         //if the new test comes from a new file (testCase)
         if (KalturaTestListener::$currentTestCase != $class) {
             //Gets the class path for the failure file
             $classPath = KAutoloader::getClassFilePath($class);
             KalturaTestListener::$failureFilePath = dirname($classPath) . "/testsData/{$class}.failures";
             KalturaTestListener::$dataFilePath = dirname($classPath) . "/testsData/{$class}.data";
             $this->writeFailuresToFile();
             //Opens the new failure file for the new test
             KalturaTestListener::$failuresFile = fopen(KalturaTestListener::$failureFilePath, "w+");
             //Change the current test case
             KalturaTestListener::$currentTestCase = $class;
             //Create new test case failures for the new test case
             KalturaTestListener::$testCaseFailures = new KalturaTestCaseFailures(KalturaTestListener::$currentTestCase);
             //TODO: get the test procedure name from the suite
             KalturaTestListener::$testCaseFailures->setTestProceduresFailures(array(new KalturaTestProcedureFailure("Unknown")));
         } else {
         }
     }
 }