public function attachToFinalCriteria(Criteria $criteria)
 {
     if (!is_null($this->get('_partner_permissions_exist'))) {
         if (is_null($this->get('_in_id'))) {
             $mandatoryParameter = "_in_id";
             throw new kCoreException("Mandatory parameter {$mandatoryParameter} missing from the filter", kCoreException::MISSING_MANDATORY_PARAMETERS, $mandatoryParameter);
         }
         $permissions = explode(',', $this->get('_partner_permissions_exist'));
         $tmpCriteria = new Criteria();
         $tmpCriteria->addSelectColumn(PermissionPeer::PARTNER_ID);
         $tmpCriteria->addAnd(PermissionPeer::NAME, $permissions, Criteria::IN);
         $ids = explode(',', $this->get('_in_id'));
         $tmpCriteria->addAnd(PermissionPeer::PARTNER_ID, $ids, Criteria::IN);
         $tmpCriteria->addAnd(PermissionPeer::STATUS, PermissionStatus::ACTIVE, Criteria::EQUAL);
         $stmt = PermissionPeer::doSelectStmt($tmpCriteria);
         $this->setIdIn($stmt->fetchAll(PDO::FETCH_COLUMN));
         $this->unsetByName('_partner_permissions_exist');
     }
     return parent::attachToFinalCriteria($criteria);
 }
 /**
  * Method to do selects.
  *
  * @param      Criteria $criteria The Criteria object used to build the SELECT statement.
  * @param      PropelPDO $con
  * @return     array Array of selected Objects
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelect(Criteria $criteria, PropelPDO $con = null)
 {
     return PermissionPeer::populateObjects(PermissionPeer::doSelectStmt($criteria, $con));
 }
Beispiel #3
0
 /**
  * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
  *
  * This will only work if the object has been saved and has a valid primary key set.
  *
  * @param      boolean $deep (optional) Whether to also de-associated any related objects.
  * @param      PropelPDO $con (optional) The PropelPDO connection to use.
  * @return     void
  * @throws     PropelException - if this object is deleted, unsaved or doesn't have pk match in db
  */
 public function reload($deep = false, PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("Cannot reload a deleted object.");
     }
     if ($this->isNew()) {
         throw new PropelException("Cannot reload an unsaved object.");
     }
     if ($con === null) {
         $con = Propel::getConnection(PermissionPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     // We don't need to alter the object instance pool; we're just modifying this instance
     // already in the pool.
     $stmt = PermissionPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
     $row = $stmt->fetch(PDO::FETCH_NUM);
     $stmt->closeCursor();
     if (!$row) {
         throw new PropelException('Cannot find matching row in the database to reload object values.');
     }
     $this->hydrate($row, 0, true);
     // rehydrate
     if ($deep) {
         // also de-associate any related objects?
         $this->collPermissionToPermissionItems = null;
         $this->lastPermissionToPermissionItemCriteria = null;
     }
     // if (deep)
 }
if ($startUpdatedAt) {
    $criteria->add(PermissionPeer::UPDATED_AT, $startUpdatedAt, Criteria::GREATER_THAN);
}
$criteria->addAscendingOrderByColumn(PermissionPeer::PARTNER_ID);
$criteria->addSelectColumn(PermissionPeer::PARTNER_ID);
$criteria->setLimit($countLimitEachLoop);
$stmt = PermissionPeer::doSelectStmt($criteria, $con);
$partners = PartnerPeer::retrieveByPKs($stmt->fetchAll(PDO::FETCH_COLUMN));
while (count($partners)) {
    foreach ($partners as $partner) {
        /* @var $partner partner */
        $partnerId = $partner->getId();
        KalturaLog::debug("Set permission [{$permissionName}] for partner id [{$partnerId}]");
        $dbPermission = PermissionPeer::getByNameAndPartner($permissionName, $partnerId);
        if (!$dbPermission) {
            $dbPermission = new Permission();
            $dbPermission->setType(PermissionType::SPECIAL_FEATURE);
            $dbPermission->setPartnerId($partnerId);
            $dbPermission->setName($permissionName);
        }
        $dbPermission->setStatus(PermissionStatus::ACTIVE);
        $dbPermission->save();
    }
    kMemoryManager::clearMemory();
    $criteria->setOffset($offset);
    $stmt = PermissionPeer::doSelectStmt($criteria, $con);
    $partners = PartnerPeer::retrieveByPKs($stmt->fetchAll(PDO::FETCH_COLUMN));
    usleep(100);
    $offset += $countLimitEachLoop;
}
KalturaLog::debug("Done");
 public static function filterDependencies($permissions, $partnerId)
 {
     $c = new Criteria();
     $c->addAnd(PermissionPeer::PARTNER_ID, $partnerId, Criteria::EQUAL);
     $c->addAnd(PermissionPeer::TYPE, array(PermissionType::PLUGIN, PermissionType::SPECIAL_FEATURE), Criteria::IN);
     $c->addAnd(PermissionPeer::STATUS, PermissionStatus::ACTIVE, Criteria::EQUAL);
     $c->addSelectColumn(PermissionPeer::NAME);
     $stmt = PermissionPeer::doSelectStmt($c);
     $additionalPartnerPermissionNames = $stmt->fetchAll(PDO::FETCH_COLUMN);
     $checkDependency = true;
     while ($checkDependency) {
         $checkDependency = false;
         $permissionNames = array();
         foreach ($permissions as $permission) {
             // create an array of permission names to assist the check
             $permissionNames[$permission->getId()] = $permission->getName();
         }
         foreach ($permissions as $key => $permission) {
             $dependsOn = trim($permission->getDependsOnPermissionNames());
             $dependsOn = explode(',', $dependsOn);
             if ($dependsOn) {
                 foreach ($dependsOn as $dependPermission) {
                     $dependPermission = trim($dependPermission);
                     if (!$dependPermission) {
                         // invalid text
                         continue;
                     }
                     if (!in_array($dependPermission, $permissionNames, true) && !in_array($dependPermission, $additionalPartnerPermissionNames, true)) {
                         // current permission depends on a non existing permission
                         unset($permissions[$key]);
                         $checkDependency = true;
                         // need to recheck because we have delete a permission
                         break;
                     }
                 }
             }
         }
     }
     return $permissions;
 }
 private static function purgeAssetFromEdgeCast(asset $asset)
 {
     // get partner
     $partnerId = $asset->getPartnerId();
     $partner = PartnerPeer::retrieveByPK($partnerId);
     if (!$partner) {
         KalturaLog::err('Cannot find partner with id [' . $partnerId . ']');
         return false;
     }
     $mediaType = $asset instanceof thumbAsset ? self::EDGE_SERVICE_HTTP_SMALL_OBJECT_MEDIA_TYPE : self::EDGE_SERVICE_HTTP_LARGE_OBJECT_MEDIA_TYPE;
     $mediaTypePathList = array();
     try {
         $mediaTypePathList[] = array('MediaType' => $mediaType, 'MediaPath' => $asset->getDownloadUrl());
         // asset download url
     } catch (Exception $e) {
         KalturaLog::err('Cannot get asset URL for asset id [' . $asset->getId() . '] - ' . $e->getMessage());
     }
     if ($asset instanceof flavorAsset) {
         // get a list of all URLs leading to the asset for purging
         $subPartnerId = $asset->getentry()->getSubpId();
         $partnerPath = myPartnerUtils::getUrlForPartner($partnerId, $subPartnerId);
         $assetId = $asset->getId();
         $serveFlavorUrl = "{$partnerPath}/serveFlavor/entryId/" . $asset->getEntryId() . "/flavorId/{$assetId}" . '*';
         // * wildcard should delete all serveFlavor urls
         $types = array(kPluginableEnumsManager::apiToCore(EdgeCastDeliveryProfileType::EDGE_CAST_HTTP), kPluginableEnumsManager::apiToCore(EdgeCastDeliveryProfileType::EDGE_CAST_RTMP));
         $deliveryProfile = $partner->getDeliveryProfileIds();
         $deliveryProfileIds = array();
         foreach ($deliveryProfile as $key => $value) {
             $deliveryProfileIds = array_merge($deliveryProfileIds, $value);
         }
         $c = new Criteria();
         $c->add(DeliveryProfilePeer::PARTNER_ID, $partnerId);
         $c->add(DeliveryProfilePeer::ID, $deliveryProfileIds, Criteria::IN);
         $c->addSelectColumn(DeliveryProfilePeer::HOST_NAME);
         $stmt = PermissionPeer::doSelectStmt($c);
         $hosts = $stmt->fetchAll(PDO::FETCH_COLUMN);
         foreach ($hosts as $host) {
             if (!empty($host)) {
                 $mediaTypePathList[] = array('MediaType' => $mediaType, 'MediaPath' => $host . $serveFlavorUrl);
             }
         }
     }
     return self::purgeFromEdgeCast($mediaTypePathList, $partner);
 }