/**
  * Cleans up the environment after running a test.
  */
 protected function tearDown()
 {
     UserRolePeer::clearInstancePool();
     PermissionPeer::clearInstancePool();
     PermissionItemPeer::clearInstancePool();
     kuserPeer::clearInstancePool();
     PartnerPeer::clearInstancePool();
     $this->client = null;
     PermissionItemPeer::setUseCriteriaFilter(false);
     foreach ($this->addedPermissionItemIds as $id) {
         try {
             $obj = PermissionItemPeer::retrieveByPK($id);
             if ($obj) {
                 $obj->delete();
             }
         } catch (PropelException $e) {
         }
     }
     PermissionItemPeer::setUseCriteriaFilter(true);
     $this->addedPermissionItemIds = array();
     parent::tearDown();
 }
 /**
  * Method perform a DELETE on the database, given a PermissionItem or Criteria object OR a primary key value.
  *
  * @param      mixed $values Criteria or PermissionItem object or primary key or array of primary keys
  *              which is used to create the DELETE statement
  * @param      PropelPDO $con the connection to use
  * @return     int 	The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
  *				if supported by native driver or if emulated using Propel.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doDelete($values, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(PermissionItemPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     if ($values instanceof Criteria) {
         // invalidate the cache for all objects of this type, since we have no
         // way of knowing (without running a query) what objects should be invalidated
         // from the cache based on this Criteria.
         PermissionItemPeer::clearInstancePool();
         // rename for clarity
         $criteria = clone $values;
     } elseif ($values instanceof PermissionItem) {
         // it's a model object
         // invalidate the cache for this single object
         PermissionItemPeer::removeInstanceFromPool($values);
         // create criteria based on pk values
         $criteria = $values->buildPkeyCriteria();
     } else {
         // it's a primary key, or an array of pks
         $criteria = new Criteria(self::DATABASE_NAME);
         $criteria->add(PermissionItemPeer::ID, (array) $values, Criteria::IN);
         // invalidate the cache for this object(s)
         foreach ((array) $values as $singleval) {
             PermissionItemPeer::removeInstanceFromPool($singleval);
         }
     }
     // Set the correct dbName
     $criteria->setDbName(self::DATABASE_NAME);
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     try {
         // use transaction because $criteria could contain info
         // for more than one table or we could emulating ON DELETE CASCADE, etc.
         $con->beginTransaction();
         $affectedRows += BasePeer::doDelete($criteria, $con);
         PermissionItemPeer::clearRelatedInstancePool();
         $con->commit();
         return $affectedRows;
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
 }
Exemplo n.º 3
0
 /**
  * Init with allowed permissions for the user in the given KS or kCurrentContext if not KS given
  * kCurrentContext::init should have been executed before!
  * @param string $ks KS to extract user and partner IDs from instead of kCurrentContext
  * @param boolean $useCache use cache or not
  * @throws TODO: add all exceptions
  */
 public static function init($useCache = null)
 {
     // verify that kCurrentContext::init has been executed since it must be used to init current context permissions
     if (!kCurrentContext::$ksPartnerUserInitialized) {
         KalturaLog::crit('kCurrentContext::initKsPartnerUser must be executed before initializing kPermissionManager');
         throw new Exception('kCurrentContext has not been initialized!', null);
     }
     // can be initialized more than once to support multirequest with different kCurrentContext parameters
     self::$initialized = false;
     self::$useCache = $useCache ? true : false;
     // copy kCurrentContext parameters (kCurrentContext::init should have been executed before)
     self::$requestedPartnerId = !self::isEmpty(kCurrentContext::$partner_id) ? kCurrentContext::$partner_id : null;
     self::$ksPartnerId = !self::isEmpty(kCurrentContext::$ks_partner_id) ? kCurrentContext::$ks_partner_id : null;
     self::$ksUserId = !self::isEmpty(kCurrentContext::$ks_uid) ? kCurrentContext::$ks_uid : null;
     self::$ksString = kCurrentContext::$ks ? kCurrentContext::$ks : null;
     self::$adminSession = !self::isEmpty(kCurrentContext::$is_admin_session) ? kCurrentContext::$is_admin_session : false;
     // clear instance pools
     //TODO: may not be needed
     UserRolePeer::clearInstancePool();
     PermissionPeer::clearInstancePool();
     PermissionItemPeer::clearInstancePool();
     PermissionToPermissionItemPeer::clearInstancePool();
     kuserPeer::clearInstancePool();
     // if ks defined - check that it is valid
     self::errorIfKsNotValid();
     // init partner, user, and role objects
     self::initPartnerUserObjects();
     // throw an error if KS partner (operating partner) is blocked
     self::errorIfPartnerBlocked();
     // init role ids
     self::initRoleIds();
     // init permissions map
     self::initPermissionsMap();
     // initialization done
     self::$initialized = true;
     return true;
 }
<?php

/**
 * @package deployment
 * @subpackage dragonfly.roles_and_permissions
 * 
 * Adds basic API object parameters that require permissions, to their associated permissions.
 * 
 * Delete from permission_to_permission_item where type = 'kApiParameterPermissionItem' to re-deploy
 */
//-- Bootstraping
error_reporting(E_ALL);
require_once dirname(__FILE__) . '/../../../bootstrap.php';
require_once ROOT_DIR . '/api_v3/bootstrap.php';
PermissionPeer::clearInstancePool();
PermissionItemPeer::clearInstancePool();
//-- Script start
// define all items
$permissionItems = array(array('object' => 'KalturaBaseEntry', 'parameter' => 'startDate', 'action' => ApiParameterPermissionItemAction::INSERT, 'permission' => PermissionName::CONTENT_MANAGE_SCHEDULE), array('object' => 'KalturaBaseEntry', 'parameter' => 'startDate', 'action' => ApiParameterPermissionItemAction::UPDATE, 'permission' => PermissionName::CONTENT_MANAGE_SCHEDULE), array('object' => 'KalturaBaseEntry', 'parameter' => 'endDate', 'action' => ApiParameterPermissionItemAction::INSERT, 'permission' => PermissionName::CONTENT_MANAGE_SCHEDULE), array('object' => 'KalturaBaseEntry', 'parameter' => 'endDate', 'action' => ApiParameterPermissionItemAction::UPDATE, 'permission' => PermissionName::CONTENT_MANAGE_SCHEDULE), array('object' => 'KalturaBaseEntry', 'parameter' => 'accessControlId', 'action' => ApiParameterPermissionItemAction::INSERT, 'permission' => PermissionName::CONTENT_MANAGE_ACCESS_CONTROL), array('object' => 'KalturaBaseEntry', 'parameter' => 'accessControlId', 'action' => ApiParameterPermissionItemAction::UPDATE, 'permission' => PermissionName::CONTENT_MANAGE_ACCESS_CONTROL), array('object' => 'KalturaBaseEntry', 'parameter' => 'categories', 'action' => ApiParameterPermissionItemAction::INSERT, 'permission' => PermissionName::CONTENT_MANAGE_ASSIGN_CATEGORIES . ',' . PermissionName::USER_SESSION_PERMISSION), array('object' => 'KalturaBaseEntry', 'parameter' => 'categories', 'action' => ApiParameterPermissionItemAction::UPDATE, 'permission' => PermissionName::CONTENT_MANAGE_ASSIGN_CATEGORIES . ',' . PermissionName::USER_SESSION_PERMISSION), array('object' => 'KalturaBaseEntry', 'parameter' => 'categoriesIds', 'action' => ApiParameterPermissionItemAction::INSERT, 'permission' => PermissionName::CONTENT_MANAGE_ASSIGN_CATEGORIES . ',' . PermissionName::USER_SESSION_PERMISSION), array('object' => 'KalturaBaseEntry', 'parameter' => 'categoriesIds', 'action' => ApiParameterPermissionItemAction::UPDATE, 'permission' => PermissionName::CONTENT_MANAGE_ASSIGN_CATEGORIES . ',' . PermissionName::USER_SESSION_PERMISSION), array('object' => 'KalturaBaseEntry', 'parameter' => 'name', 'action' => ApiParameterPermissionItemAction::UPDATE, 'permission' => PermissionName::CONTENT_MANAGE_METADATA . ',' . PermissionName::USER_SESSION_PERMISSION . ',' . PermissionName::CONTENT_MODERATE_METADATA), array('object' => 'KalturaBaseEntry', 'parameter' => 'tags', 'action' => ApiParameterPermissionItemAction::UPDATE, 'permission' => PermissionName::CONTENT_MANAGE_METADATA . ',' . PermissionName::USER_SESSION_PERMISSION . ',' . PermissionName::CONTENT_MODERATE_METADATA), array('object' => 'KalturaBaseEntry', 'parameter' => 'description', 'action' => ApiParameterPermissionItemAction::UPDATE, 'permission' => PermissionName::CONTENT_MANAGE_METADATA . ',' . PermissionName::USER_SESSION_PERMISSION . ',' . PermissionName::CONTENT_MODERATE_METADATA), array('object' => 'KalturaLiveStreamAdminEntry', 'parameter' => kApiParameterPermissionItem::ALL_VALUES_IDENTIFIER, 'action' => ApiParameterPermissionItemAction::READ, 'permission' => PermissionName::CONTENT_MANAGE_BASE), array('object' => 'KalturaLiveStreamAdminEntry', 'parameter' => kApiParameterPermissionItem::ALL_VALUES_IDENTIFIER, 'action' => ApiParameterPermissionItemAction::INSERT, 'permission' => PermissionName::CONTENT_MANAGE_BASE), array('object' => 'KalturaLiveStreamAdminEntry', 'parameter' => kApiParameterPermissionItem::ALL_VALUES_IDENTIFIER, 'action' => ApiParameterPermissionItemAction::UPDATE, 'permission' => PermissionName::CONTENT_MANAGE_BASE), array('object' => 'KalturaPartner', 'parameter' => 'secret', 'action' => ApiParameterPermissionItemAction::READ, 'permission' => PermissionName::INTEGRATION_BASE), array('object' => 'KalturaPartner', 'parameter' => 'adminSecret', 'action' => ApiParameterPermissionItemAction::READ, 'permission' => PermissionName::INTEGRATION_BASE));
// add all to required permissions
foreach ($permissionItems as $cur) {
    $item = new kApiParameterPermissionItem();
    $item->setObject($cur['object']);
    $item->setParameter($cur['parameter']);
    $item->setAction($cur['action']);
    $item->setPartnerId(PartnerPeer::GLOBAL_PARTNER);
    $item->save();
    $permissions = $cur['permission'];
    $permissions = explode(',', $permissions);
    foreach ($permissions as $permissionName) {
        if (!$permissionName) {
 public static function clearMemory()
 {
     accessControlPeer::clearInstancePool();
     kuserPeer::clearInstancePool();
     kshowPeer::clearInstancePool();
     entryPeer::clearInstancePool();
     //	    kvotePeer::clearInstancePool();
     //	    commentPeer::clearInstancePool();
     //	    flagPeer::clearInstancePool();
     //	    favoritePeer::clearInstancePool();
     //	    KshowKuserPeer::clearInstancePool();
     //	    MailJobPeer::clearInstancePool();
     SchedulerPeer::clearInstancePool();
     SchedulerWorkerPeer::clearInstancePool();
     SchedulerStatusPeer::clearInstancePool();
     SchedulerConfigPeer::clearInstancePool();
     ControlPanelCommandPeer::clearInstancePool();
     BatchJobPeer::clearInstancePool();
     //	    PriorityGroupPeer::clearInstancePool();
     BulkUploadResultPeer::clearInstancePool();
     //	    blockedEmailPeer::clearInstancePool();
     //	    conversionPeer::clearInstancePool();
     //	    flickrTokenPeer::clearInstancePool();
     PuserKuserPeer::clearInstancePool();
     //	    PuserRolePeer::clearInstancePool();
     PartnerPeer::clearInstancePool();
     //	    WidgetLogPeer::clearInstancePool();
     //	    adminKuserPeer::clearInstancePool();
     //	    notificationPeer::clearInstancePool();
     moderationPeer::clearInstancePool();
     moderationFlagPeer::clearInstancePool();
     roughcutEntryPeer::clearInstancePool();
     //	    widgetPeer::clearInstancePool();
     uiConfPeer::clearInstancePool();
     //	    PartnerStatsPeer::clearInstancePool();
     //	    PartnerActivityPeer::clearInstancePool();
     ConversionProfilePeer::clearInstancePool();
     //	    ConversionParamsPeer::clearInstancePool();
     //	    KceInstallationErrorPeer::clearInstancePool();
     FileSyncPeer::clearInstancePool();
     accessControlPeer::clearInstancePool();
     mediaInfoPeer::clearInstancePool();
     assetParamsPeer::clearInstancePool();
     assetParamsOutputPeer::clearInstancePool();
     assetPeer::clearInstancePool();
     conversionProfile2Peer::clearInstancePool();
     flavorParamsConversionProfilePeer::clearInstancePool();
     categoryPeer::clearInstancePool();
     syndicationFeedPeer::clearInstancePool();
     TrackEntryPeer::clearInstancePool();
     //	    SystemUserPeer::clearInstancePool();
     StorageProfilePeer::clearInstancePool();
     //	    EmailIngestionProfilePeer::clearInstancePool();
     UploadTokenPeer::clearInstancePool();
     //	    invalidSessionPeer::clearInstancePool();
     DynamicEnumPeer::clearInstancePool();
     UserLoginDataPeer::clearInstancePool();
     PermissionPeer::clearInstancePool();
     UserRolePeer::clearInstancePool();
     PermissionItemPeer::clearInstancePool();
     PermissionToPermissionItemPeer::clearInstancePool();
     KuserToUserRolePeer::clearInstancePool();
     $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaMemoryCleaner');
     foreach ($pluginInstances as $pluginInstance) {
         $pluginInstance->cleanMemory();
     }
     if (function_exists('gc_collect_cycles')) {
         // php 5.3 and above
         gc_collect_cycles();
     }
 }