示例#1
0
文件: Dao.php 项目: jansarmir/pimcore
 /**
  * Loads a list of predefined properties for the specicifies parameters, returns an array of Property\Predefined elements
  *
  * @return array
  */
 public function load()
 {
     $properties = array();
     $propertiesData = $this->db->fetchAll($this->model->getFilter(), $this->model->getOrder());
     foreach ($propertiesData as $propertyData) {
         $properties[] = Config::getByName($propertyData["id"]);
     }
     $this->model->setThumbnails($properties);
     return $properties;
 }
示例#2
0
 /**
  * @param string $config
  * @return Video\Thumbnail\Config|null
  */
 public function getThumbnailConfig($config)
 {
     $thumbnail = null;
     if (is_string($config)) {
         $thumbnail = Video\Thumbnail\Config::getByName($config);
     } elseif ($config instanceof Video\Thumbnail\Config) {
         $thumbnail = $config;
     }
     return $thumbnail;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // disable versioning
     Version::disable();
     // get all thumbnails
     $dir = Asset\Video\Thumbnail\Config::getWorkingDir();
     $thumbnails = array();
     $files = scandir($dir);
     foreach ($files as $file) {
         if (strpos($file, ".xml")) {
             $thumbnails[] = str_replace(".xml", "", $file);
         }
     }
     $allowedThumbs = array();
     if ($input->getOption("thumbnails")) {
         $allowedThumbs = explode(",", $input->getOption("thumbnails"));
     }
     // get only images
     $conditions = array("type = 'video'");
     if ($input->getOption("parent")) {
         $parent = Asset::getById($input->getOption("parent"));
         if ($parent instanceof Asset\Folder) {
             $conditions[] = "path LIKE '" . $parent->getFullPath() . "/%'";
         } else {
             $this->writeError($input->getOption("parent") . " is not a valid asset folder ID!");
             exit;
         }
     }
     $list = new Asset\Listing();
     $list->setCondition(implode(" AND ", $conditions));
     $total = $list->getTotalCount();
     $perLoop = 10;
     for ($i = 0; $i < ceil($total / $perLoop); $i++) {
         $list->setLimit($perLoop);
         $list->setOffset($i * $perLoop);
         $videos = $list->load();
         foreach ($videos as $video) {
             foreach ($thumbnails as $thumbnail) {
                 if (empty($allowedThumbs) && !$input->getOption("system") || in_array($thumbnail, $allowedThumbs)) {
                     $this->output->writeln("generating thumbnail for video: " . $video->getFullpath() . " | " . $video->getId() . " | Thumbnail: " . $thumbnail . " : " . formatBytes(memory_get_usage()));
                     $video->getThumbnail($thumbnail);
                     $this->waitTillFinished($video->getId(), $thumbnail);
                 }
             }
             if ($input->getOption("system")) {
                 $this->output->writeln("generating thumbnail for video: " . $video->getFullpath() . " | " . $video->getId() . " | Thumbnail: System Preview : " . formatBytes(memory_get_usage()));
                 $thumbnail = Asset\Video\Thumbnail\Config::getPreviewConfig();
                 $video->getThumbnail($thumbnail);
                 $this->waitTillFinished($video->getId(), $thumbnail);
             }
         }
     }
 }
示例#4
0
 /**
  * @param string $config
  * @return Video\Thumbnail\Config|null
  */
 public function getThumbnailConfig($config)
 {
     $thumbnail = null;
     if (is_string($config)) {
         try {
             $thumbnail = Video\Thumbnail\Config::getByName($config);
         } catch (\Exception $e) {
             \Logger::error("requested video-thumbnail " . $config . " is not defined");
             return null;
         }
     } else {
         if ($config instanceof Video\Thumbnail\Config) {
             $thumbnail = $config;
         }
     }
     return $thumbnail;
 }
$perLoop = 10;
for ($i = 0; $i < ceil($total / $perLoop); $i++) {
    $list->setLimit($perLoop);
    $list->setOffset($i * $perLoop);
    $videos = $list->load();
    foreach ($videos as $video) {
        foreach ($thumbnails as $thumbnail) {
            if (empty($allowedThumbs) && !$opts->getOption("system") || in_array($thumbnail, $allowedThumbs)) {
                echo "generating thumbnail for video: " . $video->getFullpath() . " | " . $video->getId() . " | Thumbnail: " . $thumbnail . " : " . formatBytes(memory_get_usage()) . " \n";
                $video->getThumbnail($thumbnail);
                waitTillFinished($video->getId(), $thumbnail);
            }
        }
        if ($opts->getOption("system")) {
            echo "generating thumbnail for video: " . $video->getFullpath() . " | " . $video->getId() . " | Thumbnail: System Preview : " . formatBytes(memory_get_usage()) . " \n";
            $thumbnail = Asset\Video\Thumbnail\Config::getPreviewConfig();
            $video->getThumbnail($thumbnail);
            waitTillFinished($video->getId(), $thumbnail);
        }
    }
}
function waitTillFinished($videoId, $thumbnail)
{
    $finished = false;
    // initial delay
    $video = Asset::getById($videoId);
    $thumb = $video->getThumbnail($thumbnail);
    if ($thumb["status"] != "finished") {
        sleep(20);
    }
    while (!$finished) {
 public function videoThumbnailUpdateAction()
 {
     $this->checkPermission("thumbnails");
     $pipe = Asset\Video\Thumbnail\Config::getByName($this->getParam("name"));
     $data = \Zend_Json::decode($this->getParam("configuration"));
     $items = array();
     foreach ($data as $key => $value) {
         $setter = "set" . ucfirst($key);
         if (method_exists($pipe, $setter)) {
             $pipe->{$setter}($value);
         }
         if (strpos($key, "item.") === 0) {
             $cleanKeyParts = explode(".", $key);
             $items[$cleanKeyParts[1]][$cleanKeyParts[2]] = $value;
         }
     }
     $pipe->resetItems();
     foreach ($items as $item) {
         $type = $item["type"];
         unset($item["type"]);
         $pipe->addItem($type, $item);
     }
     $pipe->save();
     $this->deleteVideoThumbnailTmpFiles($pipe);
     $this->_helper->json(array("success" => true));
 }
 public function getPreviewVideoAction()
 {
     $asset = Asset::getById($this->getParam("id"));
     $this->view->asset = $asset;
     $config = Asset\Video\Thumbnail\Config::getPreviewConfig();
     $thumbnail = $asset->getThumbnail($config, array("mp4"));
     if ($thumbnail) {
         $this->view->asset = $asset;
         $this->view->thumbnail = $thumbnail;
         if ($thumbnail["status"] == "finished") {
             $this->render("get-preview-video-display");
         } else {
             $this->render("get-preview-video-error");
         }
     } else {
         $this->render("get-preview-video-error");
     }
 }
            $name = str_replace(".xml", "", $file);
            $thumbnail = Asset\Image\Thumbnail\Config::getByName($name);
            $thumbnail = object2array($thumbnail);
            $thumbnail["id"] = $thumbnail["name"];
            unset($thumbnail["name"]);
            $json->insertOrUpdate($thumbnail, $thumbnail["id"]);
        }
    }
    // move data
    rename($dir, $legacyFolder . "/imagepipelines");
}
// VIDEO THUMBNAILS
$dir = PIMCORE_CONFIGURATION_DIRECTORY . "/videopipelines";
if (is_dir($dir)) {
    $file = Pimcore\Config::locateConfigFile("video-thumbnails");
    $json = \Pimcore\Db\JsonFileTable::get($file);
    $json->truncate();
    $files = scandir($dir);
    foreach ($files as $file) {
        if (strpos($file, ".xml")) {
            $name = str_replace(".xml", "", $file);
            $thumbnail = Asset\Video\Thumbnail\Config::getByName($name);
            $thumbnail = object2array($thumbnail);
            $thumbnail["id"] = $thumbnail["name"];
            unset($thumbnail["name"]);
            $json->insertOrUpdate($thumbnail, $thumbnail["id"]);
        }
    }
    // move data
    rename($dir, $legacyFolder . "/videopipelines");
}