error() public static method

public static error ( $m, $context = [] )
コード例 #1
0
 public static function runCrawler()
 {
     $running = Configuration::getCoreSetting('running');
     if ($running === TRUE) {
         return FALSE;
     }
     $indexDir = \LuceneSearch\Plugin::getFrontendSearchIndex();
     if ($indexDir) {
         exec('rm -Rf ' . str_replace('/index/', '/tmpindex', $indexDir));
         \Pimcore\Logger::debug('LuceneSearch: rm -Rf ' . str_replace('/index/', '/tmpindex', $indexDir));
         \Pimcore\Logger::debug('LuceneSearch: Starting crawl');
         try {
             $urls = Configuration::get('frontend.urls');
             $invalidLinkRegexesSystem = Configuration::get('frontend.invalidLinkRegexes');
             $invalidLinkRegexesEditable = Configuration::get('frontend.invalidLinkRegexesEditable');
             if (!empty($invalidLinkRegexesEditable) and !empty($invalidLinkRegexesSystem)) {
                 $invalidLinkRegexes = array_merge($invalidLinkRegexesEditable, array($invalidLinkRegexesSystem));
             } else {
                 if (!empty($invalidLinkRegexesEditable)) {
                     $invalidLinkRegexes = $invalidLinkRegexesEditable;
                 } else {
                     if (!empty($invalidLinkRegexesSystem)) {
                         $invalidLinkRegexes = array($invalidLinkRegexesSystem);
                     } else {
                         $invalidLinkRegexes = array();
                     }
                 }
             }
             self::setCrawlerState('frontend', 'started', TRUE);
             try {
                 foreach ($urls as $seed) {
                     $parser = new Parser();
                     $parser->setDepth(Configuration::get('frontend.crawler.maxLinkDepth'))->setValidLinkRegexes(Configuration::get('frontend.validLinkRegexes'))->setInvalidLinkRegexes($invalidLinkRegexes)->setSearchStartIndicator(Configuration::get('frontend.crawler.contentStartIndicator'))->setSearchEndIndicator(Configuration::get('frontend.crawler.contentEndIndicator'))->setSearchExcludeStartIndicator(Configuration::get('frontend.crawler.contentExcludeStartIndicator'))->setSearchExcludeEndIndicator(Configuration::get('frontend.crawler.contentExcludeEndIndicator'))->setAllowSubdomain(FALSE)->setAllowedSchemes(Configuration::get('frontend.allowedSchemes'))->setDownloadLimit(Configuration::get('frontend.crawler.maxDownloadLimit'))->setSeed($seed);
                     if (Configuration::get('frontend.auth.useAuth') === TRUE) {
                         $parser->setAuth(Configuration::get('frontend.auth.username'), Configuration::get('frontend.auth.password'));
                     }
                     $parser->startParser();
                     $parser->optimizeIndex();
                 }
             } catch (\Exception $e) {
             }
             self::setCrawlerState('frontend', 'finished', FALSE);
             //only remove index, if tmp exists!
             $tmpIndex = str_replace('/index', '/tmpindex', $indexDir);
             if (is_dir($tmpIndex)) {
                 exec('rm -Rf ' . $indexDir);
                 \Pimcore\Logger::debug('LuceneSearch: rm -Rf ' . $indexDir);
                 exec('cp -R ' . substr($tmpIndex, 0, -1) . ' ' . substr($indexDir, 0, -1));
                 \Pimcore\Logger::debug('LuceneSearch: cp -R ' . substr($tmpIndex, 0, -1) . ' ' . substr($indexDir, 0, -1));
                 \Pimcore\Logger::debug('LuceneSearch: replaced old index');
                 \Pimcore\Logger::info('LuceneSearch: Finished crawl');
             } else {
                 \Pimcore\Logger::error('LuceneSearch: skipped index replacing. no tmp index found.');
             }
         } catch (\Exception $e) {
             \Pimcore\Logger::error($e);
             throw $e;
         }
     }
 }
コード例 #2
0
ファイル: MysqlToolsCommand.php プロジェクト: pimcore/pimcore
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // display error message
     if (!$input->getOption("mode")) {
         $this->writeError("Please specify the mode!");
         exit;
     }
     $db = \Pimcore\Db::get();
     if ($input->getOption("mode") == "optimize") {
         $tables = $db->fetchAll("SHOW TABLES");
         foreach ($tables as $table) {
             $t = current($table);
             try {
                 Logger::debug("Running: OPTIMIZE TABLE " . $t);
                 $db->query("OPTIMIZE TABLE " . $t);
             } catch (\Exception $e) {
                 Logger::error($e);
             }
         }
     } elseif ($input->getOption("mode") == "warmup") {
         $tables = $db->fetchAll("SHOW TABLES");
         foreach ($tables as $table) {
             $t = current($table);
             try {
                 Logger::debug("Running: SELECT COUNT(*) FROM {$t}");
                 $res = $db->fetchOne("SELECT COUNT(*) FROM {$t}");
                 Logger::debug("Result: " . $res);
             } catch (\Exception $e) {
                 Logger::error($e);
             }
         }
     }
 }
コード例 #3
0
ファイル: Concrete.php プロジェクト: pimcore/pimcore
 /**
  * @param $object
  * @param bool $disableMappingExceptions
  * @param null $idMapper
  * @throws \Exception
  */
 public function reverseMap($object, $disableMappingExceptions = false, $idMapper = null)
 {
     $keys = get_object_vars($this);
     foreach ($keys as $key => $value) {
         $method = "set" . $key;
         if (method_exists($object, $method)) {
             $object->{$method}($value);
         }
     }
     //must be after generic setters above!!
     parent::reverseMap($object, $disableMappingExceptions, $idMapper);
     if (is_array($this->elements)) {
         foreach ($this->elements as $element) {
             $class = $object->getClass();
             $setter = "set" . ucfirst($element->name);
             if (method_exists($object, $setter)) {
                 $tag = $class->getFieldDefinition($element->name);
                 if ($tag) {
                     if ($class instanceof Model\Object\ClassDefinition\Data\Fieldcollections) {
                         $object->{$setter}($tag->getFromWebserviceImport($element->fieldcollection, $object, [], $idMapper));
                     } else {
                         $object->{$setter}($tag->getFromWebserviceImport($element->value, $object, [], $idMapper));
                     }
                 } else {
                     Logger::error("tag for field " . $element->name . " not found");
                 }
             } else {
                 if (!$disableMappingExceptions) {
                     throw new \Exception("No element [ " . $element->name . " ] of type [ " . $element->type . " ] found in class definition [" . $class->getId() . "] | " . $class->getName());
                 }
             }
         }
     }
 }
コード例 #4
0
ファイル: Dao.php プロジェクト: pimcore/pimcore
 /**
  *
  */
 public function save()
 {
     try {
         $data = ["id" => $this->model->getId()->getId(), "fullpath" => $this->model->getFullPath(), "maintype" => $this->model->getId()->getType(), "type" => $this->model->getType(), "subtype" => $this->model->getSubtype(), "published" => $this->model->isPublished(), "creationdate" => $this->model->getCreationDate(), "modificationdate" => $this->model->getmodificationDate(), "userowner" => $this->model->getUserOwner(), "usermodification" => $this->model->getUserModification(), "data" => $this->model->getData(), "properties" => $this->model->getProperties()];
         $this->db->insertOrUpdate("search_backend_data", $data);
     } catch (\Exception $e) {
         Logger::error($e);
     }
 }
コード例 #5
0
ファイル: WebsiteSetting.php プロジェクト: pimcore/pimcore
 /**
  * @param string $name
  * @return WebsiteSetting
  */
 public static function getByName($name, $siteId = null)
 {
     // create a tmp object to obtain the id
     $setting = new self();
     try {
         $setting->getDao()->getByName($name, $siteId);
     } catch (\Exception $e) {
         Logger::error($e);
         return null;
     }
     return $setting;
 }
コード例 #6
0
ファイル: Dao.php プロジェクト: pimcore/pimcore
 /**
  * Save object to database
  *
  * @return void
  */
 public function save()
 {
     $version = get_object_vars($this->model);
     foreach ($version as $key => $value) {
         if (in_array($key, $this->getValidTableColumns("recyclebin"))) {
             $data[$key] = $value;
         }
     }
     try {
         $this->db->insert("recyclebin", $data);
         $this->model->setId($this->db->lastInsertId());
     } catch (\Exception $e) {
         Logger::error($e);
     }
     return true;
 }
コード例 #7
0
ファイル: HttpErrorLog.php プロジェクト: pimcore/pimcore
 /**
  *
  */
 public function writeLog()
 {
     $code = (string) $this->getResponse()->getHttpResponseCode();
     $db = \Pimcore\Db::get();
     try {
         $uri = $this->getRequest()->getScheme() . "://" . $this->getRequest()->getHttpHost() . $this->getRequest()->getRequestUri();
         $exists = $db->fetchOne("SELECT date FROM http_error_log WHERE uri = ?", $uri);
         if ($exists) {
             $db->query("UPDATE http_error_log SET `count` = `count` + 1, date = ? WHERE uri = ?", [time(), $uri]);
         } else {
             $db->insert("http_error_log", ["uri" => $uri, "code" => (int) $code, "parametersGet" => serialize($_GET), "parametersPost" => serialize($_POST), "cookies" => serialize($_COOKIE), "serverVars" => serialize($_SERVER), "date" => time(), "count" => 1]);
         }
     } catch (\Exception $e) {
         Logger::error("Unable to log http error");
         Logger::error($e);
     }
 }
コード例 #8
0
ファイル: PdfReactor8.php プロジェクト: pimcore/pimcore
 protected function buildPdf(Document\PrintAbstract $document, $config)
 {
     $web2PrintConfig = Config::getWeb2PrintConfig();
     $params = [];
     $params['printermarks'] = $config->printermarks == "true";
     $params['screenResolutionImages'] = $config->screenResolutionImages == "true";
     $this->updateStatus($document->getId(), 10, "start_html_rendering");
     $html = $document->renderDocument($params);
     $this->updateStatus($document->getId(), 40, "finished_html_rendering");
     $filePath = PIMCORE_TEMPORARY_DIRECTORY . "/pdf-reactor-input-" . $document->getId() . ".html";
     file_put_contents($filePath, $html);
     $html = null;
     $this->updateStatus($document->getId(), 45, "saved_html_file");
     ini_set("default_socket_timeout", 3000);
     ini_set('max_input_time', -1);
     include_once 'Pimcore/Web2Print/Processor/api/v' . $web2PrintConfig->get('pdfreactorVersion', '8.0') . '/PDFreactor.class.php';
     $port = (string) $web2PrintConfig->pdfreactorServerPort ? (string) $web2PrintConfig->pdfreactorServerPort : "9423";
     $pdfreactor = new \PDFreactor("http://" . $web2PrintConfig->pdfreactorServer . ":" . $port . "/service/rest");
     $filePath = str_replace(PIMCORE_DOCUMENT_ROOT, "", $filePath);
     $reactorConfig = ["document" => (string) $web2PrintConfig->pdfreactorBaseUrl . $filePath, "baseURL" => (string) $web2PrintConfig->pdfreactorBaseUrl, "author" => $config->author ? $config->author : "", "title" => $config->title ? $config->title : "", "addLinks" => $config->links == "true", "addBookmarks" => $config->bookmarks == "true", "javaScriptMode" => $config->javaScriptMode, "viewerPreferences" => [$config->viewerPreference], "defaultColorSpace" => $config->colorspace, "encryption" => $config->encryption, "addTags" => $config->tags == "true", "logLevel" => $config->loglevel];
     if (trim($web2PrintConfig->pdfreactorLicence)) {
         $reactorConfig["licenseKey"] = trim($web2PrintConfig->pdfreactorLicence);
     }
     try {
         $progress = new \stdClass();
         $progress->finished = false;
         $processId = $pdfreactor->convertAsync($reactorConfig);
         while (!$progress->finished) {
             $progress = $pdfreactor->getProgress($processId);
             $this->updateStatus($document->getId(), 50 + $progress->progress / 2, "pdf_conversion");
             Logger::info("PDF converting progress: " . $progress->progress . "%");
             sleep(2);
         }
         $this->updateStatus($document->getId(), 100, "saving_pdf_document");
         $result = $pdfreactor->getDocument($processId);
         $pdf = base64_decode($result->document);
     } catch (\Exception $e) {
         Logger::error($e);
         $document->setLastGenerateMessage($e->getMessage());
         throw new \Exception("Error during REST-Request:" . $e->getMessage());
     }
     $document->setLastGenerateMessage("");
     return $pdf;
 }
コード例 #9
0
ファイル: Tree.php プロジェクト: pimcore/pimcore
 /**
  * Moves a file/directory
  *
  * @param string $sourcePath
  * @param string $destinationPath
  * @return void
  */
 public function move($sourcePath, $destinationPath)
 {
     $nameParts = explode("/", $sourcePath);
     $nameParts[count($nameParts) - 1] = Element\Service::getValidKey($nameParts[count($nameParts) - 1], "asset");
     $sourcePath = implode("/", $nameParts);
     $nameParts = explode("/", $destinationPath);
     $nameParts[count($nameParts) - 1] = Element\Service::getValidKey($nameParts[count($nameParts) - 1], "asset");
     $destinationPath = implode("/", $nameParts);
     try {
         if (dirname($sourcePath) == dirname($destinationPath)) {
             $asset = null;
             if ($asset = Asset::getByPath("/" . $destinationPath)) {
                 // If we got here, this means the destination exists, and needs to be overwritten
                 $sourceAsset = Asset::getByPath("/" . $sourcePath);
                 $asset->setData($sourceAsset->getData());
                 $sourceAsset->delete();
             }
             // see: Asset\WebDAV\File::delete() why this is necessary
             $log = Asset\WebDAV\Service::getDeleteLog();
             if (!$asset && array_key_exists("/" . $destinationPath, $log)) {
                 $asset = \Pimcore\Tool\Serialize::unserialize($log["/" . $destinationPath]["data"]);
                 if ($asset) {
                     $sourceAsset = Asset::getByPath("/" . $sourcePath);
                     $asset->setData($sourceAsset->getData());
                     $sourceAsset->delete();
                 }
             }
             if (!$asset) {
                 $asset = Asset::getByPath("/" . $sourcePath);
             }
             $asset->setFilename(basename($destinationPath));
         } else {
             $asset = Asset::getByPath("/" . $sourcePath);
             $parent = Asset::getByPath("/" . dirname($destinationPath));
             $asset->setPath($parent->getRealFullPath() . "/");
             $asset->setParentId($parent->getId());
         }
         $user = \Pimcore\Tool\Admin::getCurrentUser();
         $asset->setUserModification($user->getId());
         $asset->save();
     } catch (\Exception $e) {
         Logger::error($e);
     }
 }
コード例 #10
0
ファイル: Authentication.php プロジェクト: pimcore/pimcore
 /**
  * @static
  * @throws \Exception
  * @return User
  */
 public static function authenticateHttpBasic()
 {
     // we're using Sabre\HTTP for basic auth
     $request = \Sabre\HTTP\Sapi::getRequest();
     $response = new \Sabre\HTTP\Response();
     $auth = new \Sabre\HTTP\Auth\Basic(Tool::getHostname(), $request, $response);
     $result = $auth->getCredentials();
     if (is_array($result)) {
         list($username, $password) = $result;
         $user = self::authenticatePlaintext($username, $password);
         if ($user) {
             return $user;
         }
     }
     $auth->requireLogin();
     $response->setBody("Authentication required");
     Logger::error("Authentication Basic (WebDAV) required");
     \Sabre\HTTP\Sapi::sendResponse($response);
     die;
 }
コード例 #11
0
 /**
  * @param integer $id
  * @return Configuration
  */
 public static function getById($id)
 {
     $cacheKey = 'lucenesearch_configuration_' . $id;
     try {
         $configurationEntry = \Zend_Registry::get($cacheKey);
         if (!$configurationEntry) {
             throw new \Exception('Configuration in registry is null');
         }
     } catch (\Exception $e) {
         try {
             $configurationEntry = new self();
             \Zend_Registry::set($cacheKey, $configurationEntry);
             $configurationEntry->setId(intval($id));
             $configurationEntry->getDao()->getById();
         } catch (\Exception $e) {
             \Pimcore\Logger::error($e);
             return NULL;
         }
     }
     return $configurationEntry;
 }
コード例 #12
0
 public function paymentAction()
 {
     $gateway = $this->getModule()->getGateway();
     if (!$gateway->supportsPurchase()) {
         \Pimcore\Logger::error("OmniPay Gateway payment [" . $this->getModule()->getName() . "] does not support purchase");
         throw new \CoreShop\Exception("Gateway doesn't support purchase!");
     }
     $params = $this->getGatewayParams();
     $response = $gateway->purchase($params)->send();
     if ($response instanceof \Omnipay\Common\Message\ResponseInterface) {
         if ($response->getTransactionReference()) {
             $this->cart->setCustomIdentifier($response->getTransactionReference());
         } else {
             $this->cart->setCustomIdentifier($params['transactionId']);
         }
         $this->cart->save();
         try {
             if ($response->isSuccessful()) {
                 \Pimcore\Logger::notice("OmniPay Gateway payment [" . $this->getModule()->getName() . "]: Gateway successfully responded redirect!");
                 $this->redirect($params['returnUrl']);
             } else {
                 if ($response->isRedirect()) {
                     if ($response instanceof \Omnipay\Common\Message\RedirectResponseInterface) {
                         \Pimcore\Logger::notice("OmniPay Gateway payment [" . $this->getModule()->getName() . "]: response is a redirect. RedirectMethod: " . $response->getRedirectMethod());
                         if ($response->getRedirectMethod() === "GET") {
                             $this->redirect($response->getRedirectUrl());
                         } else {
                             $this->view->response = $response;
                             $this->_helper->viewRenderer('payment/post', null, true);
                         }
                     }
                 } else {
                     throw new \CoreShop\Exception($response->getMessage());
                 }
             }
         } catch (\Exception $e) {
             \Pimcore\Logger::error("OmniPay Gateway payment [" . $this->getModule()->getName() . "] Error: " . $e->getMessage());
         }
     }
 }
コード例 #13
0
ファイル: Image.php プロジェクト: pimcore/pimcore
 /**
  * @return void
  */
 protected function update()
 {
     // only do this if the file exists and contains data
     if ($this->getDataChanged() || !$this->getCustomSetting("imageDimensionsCalculated")) {
         try {
             // save the current data into a tmp file to calculate the dimensions, otherwise updates wouldn't be updated
             // because the file is written in parent::update();
             $tmpFile = $this->getTemporaryFile();
             $dimensions = $this->getDimensions($tmpFile, true);
             unlink($tmpFile);
             if ($dimensions && $dimensions["width"]) {
                 $this->setCustomSetting("imageWidth", $dimensions["width"]);
                 $this->setCustomSetting("imageHeight", $dimensions["height"]);
             }
         } catch (\Exception $e) {
             Logger::error("Problem getting the dimensions of the image with ID " . $this->getId());
         }
         // this is to be downward compatible so that the controller can check if the dimensions are already calculated
         // and also to just do the calculation once, because the calculation can fail, an then the controller tries to
         // calculate the dimensions on every request an also will create a version, ...
         $this->setCustomSetting("imageDimensionsCalculated", true);
     }
     parent::update();
     $this->clearThumbnails();
     // now directly create "system" thumbnails (eg. for the tree, ...)
     if ($this->getDataChanged()) {
         try {
             $path = $this->getThumbnail(Image\Thumbnail\Config::getPreviewConfig())->getFileSystemPath();
             // set the modification time of the thumbnail to the same time from the asset
             // so that the thumbnail check doesn't fail in Asset\Image\Thumbnail\Processor::process();
             // we need the @ in front of touch because of some stream wrapper (eg. s3) which don't support touch()
             @touch($path, $this->getModificationDate());
         } catch (\Exception $e) {
             Logger::error("Problem while creating system-thumbnails for image " . $this->getRealFullPath());
             Logger::error($e);
         }
     }
 }
コード例 #14
0
ファイル: QrCode.php プロジェクト: pimcore/pimcore
 /**
  * @param \Zend_Controller_Request_Abstract $request
  */
 public function routeStartup(\Zend_Controller_Request_Abstract $request)
 {
     if (preg_match("@^/qr~-~code/([a-zA-Z0-9_\\-]+)@", $request->getPathInfo(), $matches)) {
         if (array_key_exists(1, $matches) && !empty($matches[1])) {
             $code = Tool\Qrcode\Config::getByName($matches[1]);
             if ($code) {
                 $url = $code->getUrl();
                 if ($code->getGoogleAnalytics()) {
                     $glue = "?";
                     if (strpos($url, "?")) {
                         $glue = "&";
                     }
                     $url .= $glue;
                     $url .= "utm_source=Mobile&utm_medium=QR-Code&utm_campaign=" . $code->getName();
                 }
                 header("Location: " . $url, true, 302);
                 exit;
             } else {
                 Logger::error("called an QR code but '" . $matches[1] . " is not a code in the system.");
             }
         }
     }
 }
コード例 #15
0
ファイル: Config.php プロジェクト: pimcore/pimcore
 /**
  * @param bool $forceReload
  * @return array|null
  */
 public static function getWorkflowManagementConfig($forceReload = false)
 {
     $config = null;
     if (\Zend_Registry::isRegistered("pimcore_config_workflowmanagement") && !$forceReload) {
         $config = \Zend_Registry::get("pimcore_config_workflowmanagement");
     } else {
         try {
             $file = \Pimcore\Config::locateConfigFile("workflowmanagement.php");
             if (is_file($file)) {
                 $config = (include $file);
                 if (is_array($config)) {
                     self::setWorkflowManagementConfig($config);
                 } else {
                     Logger::error("{$file} exists but it is not a valid PHP array configuration.");
                 }
             }
         } catch (\Exception $e) {
             $file = \Pimcore\Config::locateConfigFile("workflowmanagement.php");
             Logger::emergency("Cannot find workflow configuration, should be located at: " . $file);
         }
     }
     return $config;
 }
コード例 #16
0
ファイル: WkHtmlToPdf.php プロジェクト: pimcore/pimcore
 protected function buildPdf(Document\PrintAbstract $document, $config)
 {
     $web2printConfig = Config::getWeb2PrintConfig();
     $params = [];
     $this->updateStatus($document->getId(), 10, "start_html_rendering");
     $html = $document->renderDocument($params);
     $placeholder = new \Pimcore\Placeholder();
     $html = $placeholder->replacePlaceholders($html);
     $html = \Pimcore\Helper\Mail::setAbsolutePaths($html, $document, $web2printConfig->wkhtml2pdfHostname);
     $this->updateStatus($document->getId(), 40, "finished_html_rendering");
     file_put_contents(PIMCORE_TEMPORARY_DIRECTORY . DIRECTORY_SEPARATOR . "wkhtmltorpdf-input.html", $html);
     $this->updateStatus($document->getId(), 45, "saved_html_file");
     try {
         $this->updateStatus($document->getId(), 50, "pdf_conversion");
         $pdf = $this->fromStringToStream($html);
         $this->updateStatus($document->getId(), 100, "saving_pdf_document");
     } catch (\Exception $e) {
         Logger::error($e);
         $document->setLastGenerateMessage($e->getMessage());
         throw new \Exception("Error during REST-Request:" . $e->getMessage());
     }
     $document->setLastGenerateMessage("");
     return $pdf;
 }
コード例 #17
0
ファイル: Dao.php プロジェクト: pimcore/pimcore
    /**
     *
     */
    public function createLocalizedViews()
    {
        // init
        $languages = Tool::getValidLanguages();
        $defaultTable = 'object_query_' . $this->model->getClass()->getId();
        $db = $this->db;
        /**
         * macro for creating ifnull statement
         * @param string $field
         * @param array  $languages
         *
         * @return string
         */
        $getFallbackValue = function ($field, array $languages) use(&$getFallbackValue, $db) {
            // init
            $lang = array_shift($languages);
            // get fallback for current language
            $fallback = count($languages) > 0 ? $getFallbackValue($field, $languages) : 'null';
            // create query
            $sql = sprintf('ifnull(`%s`.`%s`, %s)', $lang, $field, $fallback);
            return $fallback !== 'null' ? $sql : $db->quoteIdentifier($lang) . '.' . $db->quoteIdentifier($field);
        };
        foreach ($languages as $language) {
            try {
                $tablename = $this->getQueryTableName() . "_" . $language;
                // get available columns
                $viewColumns = array_merge($this->db->fetchAll('SHOW COLUMNS FROM `' . $defaultTable . '`'), $this->db->fetchAll('SHOW COLUMNS FROM `objects`'));
                $localizedColumns = $this->db->fetchAll('SHOW COLUMNS FROM `' . $tablename . '`');
                // get view fields
                $viewFields = [];
                foreach ($viewColumns as $row) {
                    $viewFields[] = $this->db->quoteIdentifier($row['Field']);
                }
                // create fallback select
                $localizedFields = [];
                $fallbackLanguages = array_unique(Tool::getFallbackLanguagesFor($language));
                array_unshift($fallbackLanguages, $language);
                foreach ($localizedColumns as $row) {
                    $localizedFields[] = $getFallbackValue($row['Field'], $fallbackLanguages) . sprintf(' as "%s"', $row['Field']);
                }
                // create view select fields
                $selectViewFields = implode(',', array_merge($viewFields, $localizedFields));
                // create view
                $viewQuery = <<<QUERY
CREATE OR REPLACE VIEW `object_localized_{$this->model->getClass()->getId()}_{$language}` AS

SELECT {$selectViewFields}
FROM `{$defaultTable}`
    JOIN `objects`
        ON (`objects`.`o_id` = `{$defaultTable}`.`oo_id`)
QUERY;
                // join fallback languages
                foreach ($fallbackLanguages as $lang) {
                    $viewQuery .= <<<QUERY
LEFT JOIN {$this->getQueryTableName()}_{$lang} as {$lang}
    ON( 1
        AND {$defaultTable}.oo_id = {$lang}.ooo_id
    )
QUERY;
                }
                // execute
                $this->db->query($viewQuery);
            } catch (\Exception $e) {
                Logger::error($e);
            }
        }
    }
コード例 #18
0
ファイル: Procedural.php プロジェクト: pimcore/pimcore
 /**
  *
  */
 public function run()
 {
     $this->setLastExecution();
     foreach ($this->jobs as $job) {
         $job->lock();
         Logger::info("Executing job with ID: " . $job->getId());
         try {
             $job->execute();
             Logger::info("Finished job with ID: " . $job->getId());
         } catch (\Exception $e) {
             Logger::error("Failed to execute job with id: " . $job->getId());
             Logger::error($e);
         }
         $job->unlock();
     }
 }
コード例 #19
0
ファイル: MysqlTable.php プロジェクト: pimcore/pimcore
 /**
  * Clean some cache records
  *
  * Available modes are :
  * 'all' (default)  => remove all cache entries ($tags is not used)
  * 'old'            => remove too old cache entries ($tags is not used)
  * 'matchingTag'    => remove cache entries matching all given tags
  *                     ($tags can be an array of strings or a single string)
  * 'notMatchingTag' => remove cache entries not matching one of the given tags
  *                     ($tags can be an array of strings or a single string)
  *
  * @param  string $mode Clean mode
  * @param  array  $tags Array of tags
  * @return boolean True if no problem
  */
 public function clean($mode = \Zend_Cache::CLEANING_MODE_ALL, $tags = [])
 {
     if ($mode == \Zend_Cache::CLEANING_MODE_ALL) {
         $this->truncate();
     }
     if ($mode == \Zend_Cache::CLEANING_MODE_OLD) {
         $this->getDb()->delete("cache", "expire < unix_timestamp() OR mtime < (unix_timestamp()-864000)");
     }
     if ($mode == \Zend_Cache::CLEANING_MODE_MATCHING_TAG || $mode == \Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG) {
         foreach ($tags as $tag) {
             $items = $this->getItemsByTag($tag);
             $quotedIds = [];
             $this->getDb()->beginTransaction();
             try {
                 foreach ($items as $item) {
                     // We call delete directly here because the ID in the cache is already specific for this site
                     $quotedId = $this->getDb()->quote($item);
                     $this->getDb()->delete("cache", "id = " . $quotedId);
                     $quotedIds[] = $quotedId;
                 }
                 if (count($quotedIds) > 0) {
                     $this->getDb()->delete("cache_tags", "id IN (" . implode(",", $quotedIds) . ")");
                 }
                 $this->getDb()->commit();
             } catch (\Exception $e) {
                 Logger::error($e);
                 $this->getDb()->rollBack();
                 $this->truncate();
             }
         }
     }
     if ($mode == \Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG) {
         $condParts = ["1=1"];
         foreach ($tags as $tag) {
             $condParts[] = "tag != '" . $tag . "'";
         }
         $itemIds = $this->getDb()->fetchCol("SELECT id FROM cache_tags WHERE " . implode(" AND ", $condParts));
         foreach ($itemIds as $item) {
             $this->remove($item);
         }
     }
     return true;
 }
コード例 #20
0
ファイル: Analytics.php プロジェクト: pimcore/pimcore
 /**
  * @param $path
  */
 public static function trackPageView($path)
 {
     Logger::error("Pimcore_Google_Analytics::trackPageView() is unsupported as of version 2.0.1");
 }
コード例 #21
0
ファイル: Data.php プロジェクト: pimcore/pimcore
 /**
  * @param $element
  * @return $this
  */
 public function setDataFromElement($element)
 {
     $this->data = null;
     $this->id = new Data\Id($element);
     $this->fullPath = $element->getRealFullPath();
     $this->creationDate = $element->getCreationDate();
     $this->modificationDate = $element->getModificationDate();
     $this->userModification = $element->getUserModification();
     $this->userOwner = $element->getUserOwner();
     $this->type = $element->getType();
     if ($element instanceof Object\Concrete) {
         $this->subtype = $element->getClassName();
     } else {
         $this->subtype = $this->type;
     }
     $this->properties = "";
     $properties = $element->getProperties();
     if (is_array($properties)) {
         foreach ($properties as $nextProperty) {
             $pData = (string) $nextProperty->getData();
             if ($nextProperty->getName() == "bool") {
                 $pData = $pData ? "true" : "false";
             }
             $this->properties .= $nextProperty->getName() . ":" . $pData . " ";
         }
     }
     $this->data = "";
     if ($element instanceof Document) {
         if ($element instanceof Document\Folder) {
             $this->data = $element->getKey();
             $this->published = true;
         } elseif ($element instanceof Document\Link) {
             $this->published = $element->isPublished();
             $this->data = $element->getTitle() . " " . $element->getHref();
         } elseif ($element instanceof Document\PageSnippet) {
             $this->published = $element->isPublished();
             $elements = $element->getElements();
             if (is_array($elements) && !empty($elements)) {
                 foreach ($elements as $tag) {
                     if ($tag instanceof Document\Tag\TagInterface) {
                         ob_start();
                         $this->data .= strip_tags($tag->frontend()) . " ";
                         $this->data .= ob_get_clean();
                     }
                 }
             }
             if ($element instanceof Document\Page) {
                 $this->published = $element->isPublished();
                 $this->data .= " " . $element->getTitle() . " " . $element->getDescription() . " " . $element->getPrettyUrl();
             }
         }
     } elseif ($element instanceof Asset) {
         $this->data = $element->getFilename();
         $elementMetadata = $element->getMetadata();
         if (is_array($elementMetadata)) {
             foreach ($elementMetadata as $md) {
                 if (is_scalar($md['data'])) {
                     $this->data .= " " . $md["name"] . ":" . $md["data"];
                 }
             }
         }
         if ($element instanceof Asset\Document && \Pimcore\Document::isAvailable()) {
             if (\Pimcore\Document::isFileTypeSupported($element->getFilename())) {
                 try {
                     $contentText = $element->getText();
                     $contentText = Encoding::toUTF8($contentText);
                     $contentText = str_replace(["\r\n", "\r", "\n", "\t", "\f"], " ", $contentText);
                     $contentText = preg_replace("/[ ]+/", " ", $contentText);
                     $this->data .= " " . $contentText;
                 } catch (\Exception $e) {
                     Logger::error($e);
                 }
             }
         } elseif ($element instanceof Asset\Text) {
             try {
                 $contentText = $element->getData();
                 $contentText = Encoding::toUTF8($contentText);
                 $this->data .= " " . $contentText;
             } catch (\Exception $e) {
                 Logger::error($e);
             }
         } elseif ($element instanceof Asset\Image) {
             try {
                 $metaData = array_merge($element->getEXIFData(), $element->getIPTCData());
                 foreach ($metaData as $key => $value) {
                     $this->data .= " " . $key . " : " . $value;
                 }
             } catch (\Exception $e) {
                 Logger::error($e);
             }
         }
         $this->published = true;
     } elseif ($element instanceof Object\AbstractObject) {
         if ($element instanceof Object\Concrete) {
             $getInheritedValues = Object\AbstractObject::doGetInheritedValues();
             Object\AbstractObject::setGetInheritedValues(true);
             $this->published = $element->isPublished();
             foreach ($element->getClass()->getFieldDefinitions() as $key => $value) {
                 $this->data .= $value->getDataForSearchIndex($element) . " ";
             }
             Object\AbstractObject::setGetInheritedValues($getInheritedValues);
         } elseif ($element instanceof Object\Folder) {
             $this->data = $element->getKey();
             $this->published = true;
         }
     } else {
         Logger::crit("Search\\Backend\\Data received an unknown element!");
     }
     if ($element instanceof Element\ElementInterface) {
         $this->data = "ID: " . $element->getId() . "  \nPath: " . $this->getFullPath() . "  \n" . $this->cleanupData($this->data);
     }
     return $this;
 }
コード例 #22
0
ファイル: ImageThumbnail.php プロジェクト: pimcore/pimcore
 /**
  *
  */
 public function generate()
 {
     $errorImage = PIMCORE_PATH . '/static6/img/filetype-not-supported.png';
     $deferred = false;
     $generated = false;
     if (!$this->asset) {
         $this->filesystemPath = $errorImage;
     } elseif (!$this->filesystemPath) {
         $cs = $this->asset->getCustomSetting("image_thumbnail_time");
         $im = $this->asset->getCustomSetting("image_thumbnail_asset");
         if ($im || $this->imageAsset) {
             if ($this->imageAsset) {
                 $im = $this->imageAsset;
             } else {
                 $im = Model\Asset::getById($im);
             }
             if ($im instanceof Image) {
                 $imageThumbnail = $im->getThumbnail($this->getConfig());
                 $this->filesystemPath = $imageThumbnail->getFileSystemPath();
             }
         }
         if (!$this->filesystemPath) {
             $timeOffset = $this->timeOffset;
             if (!$this->timeOffset && $cs) {
                 $timeOffset = $cs;
             }
             // fallback
             if (!$timeOffset) {
                 $timeOffset = ceil($this->asset->getDuration() / 3);
             }
             $converter = \Pimcore\Video::getInstance();
             $converter->load($this->asset->getFileSystemPath());
             $path = PIMCORE_TEMPORARY_DIRECTORY . "/video-image-cache/video_" . $this->asset->getId() . "__thumbnail_" . $timeOffset . ".png";
             if (!is_dir(dirname($path))) {
                 File::mkdir(dirname($path));
             }
             if (!is_file($path)) {
                 $lockKey = "video_image_thumbnail_" . $this->asset->getId() . "_" . $timeOffset;
                 Model\Tool\Lock::acquire($lockKey);
                 // after we got the lock, check again if the image exists in the meantime - if not - generate it
                 if (!is_file($path)) {
                     $converter->saveImage($path, $timeOffset);
                     $generated = true;
                 }
                 Model\Tool\Lock::release($lockKey);
             }
             if ($this->getConfig()) {
                 $this->getConfig()->setFilenameSuffix("time-" . $timeOffset);
                 try {
                     $path = Image\Thumbnail\Processor::process($this->asset, $this->getConfig(), $path, $deferred, true, $generated);
                 } catch (\Exception $e) {
                     Logger::error("Couldn't create image-thumbnail of video " . $this->asset->getRealFullPath());
                     Logger::error($e);
                     $path = $errorImage;
                 }
             }
             $this->filesystemPath = $path;
         }
         \Pimcore::getEventManager()->trigger("asset.video.image-thumbnail", $this, ["deferred" => $deferred, "generated" => $generated]);
     }
 }
コード例 #23
0
ファイル: ElementController.php プロジェクト: pimcore/pimcore
 public function getNicePathAction()
 {
     $source = \Zend_Json::decode($this->getParam("source"));
     if ($source["type"] != "object") {
         throw new \Exception("currently only objects as source elements are supported");
     }
     $result = [];
     $id = $source["id"];
     $source = Object\Concrete::getById($id);
     if ($this->getParam("context")) {
         $context = \Zend_Json::decode($this->getParam("context"));
     } else {
         $context = [];
     }
     $ownerType = $context["containerType"];
     $fieldname = $context["fieldname"];
     if ($ownerType == "object") {
         $fd = $source->getClass()->getFieldDefinition($fieldname);
     } elseif ($ownerType == "localizedfield") {
         $fd = $source->getClass()->getFieldDefinition("localizedfields")->getFieldDefinition($fieldname);
     } elseif ($ownerType == "objectbrick") {
         $fdBrick = Object\Objectbrick\Definition::getByKey($context["containerKey"]);
         $fd = $fdBrick->getFieldDefinition($fieldname);
     } elseif ($ownerType == "fieldcollection") {
         $containerKey = $context["containerKey"];
         $fdCollection = Object\Fieldcollection\Definition::getByKey($containerKey);
         if ($context["subContainerType"] == "localizedfield") {
             $fdLocalizedFields = $fdCollection->getFieldDefinition("localizedfields");
             $fd = $fdLocalizedFields->getFieldDefinition($fieldname);
         } else {
             $fd = $fdCollection->getFieldDefinition($fieldname);
         }
     }
     if (method_exists($fd, "getPathFormatterClass")) {
         $formatterClass = $fd->getPathFormatterClass();
         if (Pimcore\Tool::classExists($formatterClass)) {
             $targets = \Zend_Json::decode($this->getParam("targets"));
             $result = call_user_func($formatterClass . "::formatPath", $result, $source, $targets, ["fd" => $fd, "context" => $context]);
         } else {
             Logger::error("Formatter Class does not exist: " . $formatterClass);
         }
     }
     $this->_helper->json(["success" => true, "data" => $result]);
 }
コード例 #24
0
ファイル: Adapter.php プロジェクト: pimcore/pimcore
 /**
  * @param  $width
  * @param  $height
  * @param string $orientation
  * @return self
  */
 public function cover($width, $height, $orientation = "center", $doNotScaleUp = true)
 {
     $scaleUp = $doNotScaleUp ? false : true;
     $ratio = $this->getWidth() / $this->getHeight();
     if ($width / $height > $ratio) {
         $this->scaleByWidth($width, $scaleUp);
     } else {
         $this->scaleByHeight($height, $scaleUp);
     }
     if ($orientation == "center") {
         $cropX = ($this->getWidth() - $width) / 2;
         $cropY = ($this->getHeight() - $height) / 2;
     } elseif ($orientation == "topleft") {
         $cropX = 0;
         $cropY = 0;
     } elseif ($orientation == "topright") {
         $cropX = $this->getWidth() - $width;
         $cropY = 0;
     } elseif ($orientation == "bottomleft") {
         $cropX = 0;
         $cropY = $this->getHeight() - $height;
     } elseif ($orientation == "bottomright") {
         $cropX = $this->getWidth() - $width;
         $cropY = $this->getHeight() - $height;
     } elseif ($orientation == "centerleft") {
         $cropX = 0;
         $cropY = ($this->getHeight() - $height) / 2;
     } elseif ($orientation == "centerright") {
         $cropX = $this->getWidth() - $width;
         $cropY = ($this->getHeight() - $height) / 2;
     } elseif ($orientation == "topcenter") {
         $cropX = ($this->getWidth() - $width) / 2;
         $cropY = 0;
     } elseif ($orientation == "bottomcenter") {
         $cropX = ($this->getWidth() - $width) / 2;
         $cropY = $this->getHeight() - $height;
     } else {
         $cropX = null;
         $cropY = null;
     }
     if ($cropX !== null && $cropY !== null) {
         $this->crop($cropX, $cropY, $width, $height);
     } else {
         Logger::error("Cropping not processed, because X or Y is not defined or null, proceeding with next step");
     }
     return $this;
 }
コード例 #25
0
ファイル: AbstractObject.php プロジェクト: pimcore/pimcore
 /**
  * @return $this
  * @throws \Exception
  */
 public function save()
 {
     $isUpdate = false;
     if ($this->getId()) {
         $isUpdate = true;
         \Pimcore::getEventManager()->trigger("object.preUpdate", $this);
     } else {
         \Pimcore::getEventManager()->trigger("object.preAdd", $this);
     }
     $this->correctPath();
     // we wrap the save actions in a loop here, so that we can restart the database transactions in the case it fails
     // if a transaction fails it gets restarted $maxRetries times, then the exception is thrown out
     // this is especially useful to avoid problems with deadlocks in multi-threaded environments (forked workers, ...)
     $maxRetries = 5;
     for ($retries = 0; $retries < $maxRetries; $retries++) {
         // be sure that unpublished objects in relations are saved also in frontend mode, eg. in importers, ...
         $hideUnpublishedBackup = self::getHideUnpublished();
         self::setHideUnpublished(false);
         $this->beginTransaction();
         try {
             if (!in_array($this->getType(), self::$types)) {
                 throw new \Exception("invalid object type given: [" . $this->getType() . "]");
             }
             if (!$isUpdate) {
                 $this->getDao()->create();
             }
             // get the old path from the database before the update is done
             $oldPath = null;
             if ($isUpdate) {
                 $oldPath = $this->getDao()->getCurrentFullPath();
             }
             // if the old path is different from the new path, update all children
             // we need to do the update of the children's path before $this->update() because the
             // inheritance helper needs the correct paths of the children in InheritanceHelper::buildTree()
             $updatedChildren = [];
             if ($oldPath && $oldPath != $this->getRealFullPath()) {
                 $this->getDao()->updateWorkspaces();
                 $updatedChildren = $this->getDao()->updateChildsPaths($oldPath);
             }
             $this->update();
             self::setHideUnpublished($hideUnpublishedBackup);
             $this->commit();
             break;
             // transaction was successfully completed, so we cancel the loop here -> no restart required
         } catch (\Exception $e) {
             try {
                 $this->rollBack();
             } catch (\Exception $er) {
                 // PDO adapter throws exceptions if rollback fails
                 Logger::info($er);
             }
             if ($e instanceof Model\Element\ValidationException) {
                 throw $e;
             }
             // set "HideUnpublished" back to the value it was originally
             self::setHideUnpublished($hideUnpublishedBackup);
             // we try to start the transaction $maxRetries times again (deadlocks, ...)
             if ($retries < $maxRetries - 1) {
                 $run = $retries + 1;
                 $waitTime = 100000;
                 // microseconds
                 Logger::warn("Unable to finish transaction (" . $run . ". run) because of the following reason '" . $e->getMessage() . "'. --> Retrying in " . $waitTime . " microseconds ... (" . ($run + 1) . " of " . $maxRetries . ")");
                 usleep($waitTime);
                 // wait specified time until we restart the transaction
             } else {
                 // if the transaction still fail after $maxRetries retries, we throw out the exception
                 Logger::error("Finally giving up restarting the same transaction again and again, last message: " . $e->getMessage());
                 throw $e;
             }
         }
     }
     $additionalTags = [];
     if (isset($updatedChildren) && is_array($updatedChildren)) {
         foreach ($updatedChildren as $objectId) {
             $tag = "object_" . $objectId;
             $additionalTags[] = $tag;
             // remove the child also from registry (internal cache) to avoid path inconsistencies during long running scripts, such as CLI
             \Zend_Registry::set($tag, null);
         }
     }
     $this->clearDependentCache($additionalTags);
     if ($isUpdate) {
         \Pimcore::getEventManager()->trigger("object.postUpdate", $this);
     } else {
         \Pimcore::getEventManager()->trigger("object.postAdd", $this);
     }
     return $this;
 }
コード例 #26
0
ファイル: Tool.php プロジェクト: krugerke/pimcore
 /**
  * @static
  * @param  $sourceClassName
  * @return string
  */
 public static function getModelClassMapping($sourceClassName)
 {
     $targetClassName = $sourceClassName;
     $lookupName = str_replace(["\\Pimcore\\Model\\", "\\"], ["", "_"], $sourceClassName);
     $lookupName = ltrim($lookupName, "\\_");
     if ($map = Config::getModelClassMappingConfig()) {
         $tmpClassName = $map->{$lookupName};
         if ($tmpClassName) {
             $tmpClassName = "\\" . ltrim($tmpClassName, "\\");
             if (self::classExists($tmpClassName)) {
                 if (is_subclass_of($tmpClassName, $sourceClassName)) {
                     $targetClassName = "\\" . ltrim($tmpClassName, "\\");
                     // ensure class is in global namespace
                 } else {
                     \Logger::error("Classmapping for " . $sourceClassName . " failed. '" . $tmpClassName . " is not a subclass of '" . $sourceClassName . "'. " . $tmpClassName . " has to extend " . $sourceClassName);
                 }
             } else {
                 \Logger::error("Classmapping for " . $sourceClassName . " failed. Cannot find class '" . $tmpClassName . "'");
             }
         }
     }
     return $targetClassName;
 }
コード例 #27
0
ファイル: Session.php プロジェクト: pimcore/pimcore
 /**
  * @param string $namespace
  * @param bool $readOnly
  * @return \Zend_Session_Namespace
  * @throws \Zend_Session_Exception
  */
 public static function get($namespace = "pimcore_admin", $readOnly = false)
 {
     $initSession = !\Zend_Session::isStarted();
     $forceStart = !$readOnly;
     // we don't force the session to start in read-only mode (default behavior)
     $sName = self::getOption("name");
     if (self::backupForeignSession()) {
         $initSession = true;
         $forceStart = true;
     }
     if ($initSession) {
         \Zend_Session::setOptions(self::$options);
     }
     try {
         try {
             if ($initSession) {
                 // only set the session id if the cookie isn't present, otherwise Set-Cookie is always in the headers
                 if (array_key_exists($sName, $_REQUEST) && !empty($_REQUEST[$sName]) && (!array_key_exists($sName, $_COOKIE) || empty($_COOKIE[$sName]))) {
                     // get zend_session work with session-id via get (since SwfUpload doesn't support cookies)
                     \Zend_Session::setId($_REQUEST[$sName]);
                 }
             }
         } catch (\Exception $e) {
             Logger::error("Problem while starting session");
             Logger::error($e);
         }
     } catch (\Exception $e) {
         Logger::emergency("there is a problem with admin session");
         die;
     }
     if ($initSession) {
         \Zend_Session::start();
     }
     if ($forceStart) {
         @session_start();
         self::$sessionCookieCleanupNeeded = true;
     }
     if (!array_key_exists($namespace, self::$sessions) || !self::$sessions[$namespace] instanceof \Zend_Session_Namespace) {
         try {
             self::$sessions[$namespace] = new Session\Container($namespace);
         } catch (\Exception $e) {
             // invalid session, regenerate the session, and return a dummy object
             \Zend_Session::regenerateId();
             return new \stdClass();
         }
     }
     self::$openedSessions++;
     self::$sessions[$namespace]->unlock();
     return self::$sessions[$namespace];
 }
コード例 #28
0
ファイル: Config.php プロジェクト: pimcore/pimcore
 /**
  * @param $config
  * @return self|bool
  */
 public static function getByAutoDetect($config)
 {
     $thumbnail = null;
     if (is_string($config)) {
         try {
             $thumbnail = self::getByName($config);
         } catch (\Exception $e) {
             Logger::error("requested thumbnail " . $config . " is not defined");
             return false;
         }
     } elseif (is_array($config)) {
         // check if it is a legacy config or a new one
         if (array_key_exists("items", $config)) {
             $thumbnail = self::getByArrayConfig($config);
         } else {
             $thumbnail = self::getByLegacyConfig($config);
         }
     } elseif ($config instanceof self) {
         $thumbnail = $config;
     }
     return $thumbnail;
 }
コード例 #29
0
ファイル: Backup.php プロジェクト: ChristophWurst/pimcore
 /**
  * @param $name
  * @param $type
  * @return array
  */
 public function mysqlData($name, $type)
 {
     $db = Db::reset();
     $dumpData = "\n\n";
     $name = $db->quoteTableAs($name);
     if ($type != "VIEW") {
         // backup tables
         $tableData = $db->fetchAll("SELECT * FROM " . $name);
         foreach ($tableData as $row) {
             $cells = array();
             foreach ($row as $cell) {
                 if (is_string($cell)) {
                     $cell = $db->quote($cell);
                 } else {
                     if ($cell === null) {
                         $cell = "NULL";
                     }
                 }
                 $cells[] = $cell;
             }
             $dumpData .= "INSERT INTO " . $name . " VALUES (" . implode(",", $cells) . ");";
             $dumpData .= "\n";
         }
     } else {
         // dump view structure
         $dumpData .= "\n\n";
         $dumpData .= "DROP VIEW IF EXISTS " . $name . ";";
         $dumpData .= "\n";
         try {
             $viewData = $db->fetchRow("SHOW CREATE VIEW " . $name);
             $dumpData .= $viewData["Create View"] . ";";
         } catch (\Exception $e) {
             \Logger::error($e);
         }
     }
     $dumpData .= "\n\n";
     $h = fopen(PIMCORE_SYSTEM_TEMP_DIRECTORY . "/backup-dump.sql", "a+");
     fwrite($h, $dumpData);
     fclose($h);
     return array("success" => true);
 }
コード例 #30
0
ファイル: Config.php プロジェクト: pimcore/pimcore
 /** Returns the element tree config for the given config name
  * @param $name
  * @return array
  */
 protected static function getRuntimeElementTreeConfig($name)
 {
     $masterConfig = self::getPerspectivesConfig()->toArray();
     $config = $masterConfig[$name];
     if (!$config) {
         $config = [];
     }
     $tmpResult = $config["elementTree"];
     if (is_null($tmpResult)) {
         $tmpResult = [];
     }
     $result = [];
     $cfConfigMapping = [];
     $cvConfigs = Tool::getCustomViewConfig();
     if ($cvConfigs) {
         foreach ($cvConfigs as $node) {
             $tmpData = $node;
             if (!isset($tmpData["id"])) {
                 Logger::error("custom view ID is missing " . var_export($tmpData, true));
                 continue;
             }
             if ($tmpData["hidden"]) {
                 continue;
             }
             // backwards compatibility
             $treeType = $tmpData["treetype"] ? $tmpData["treetype"] : "object";
             $rootNode = Model\Element\Service::getElementByPath($treeType, $tmpData["rootfolder"]);
             if ($rootNode) {
                 $tmpData["type"] = "customview";
                 $tmpData["rootId"] = $rootNode->getId();
                 $tmpData["allowedClasses"] = $tmpData["classes"] ? explode(",", $tmpData["classes"]) : null;
                 $tmpData["showroot"] = (bool) $tmpData["showroot"];
                 $customViewId = $tmpData["id"];
                 $cfConfigMapping[$customViewId] = $tmpData;
             }
         }
     }
     foreach ($tmpResult as $resultItem) {
         if ($resultItem["hidden"]) {
             continue;
         }
         if ($resultItem["type"] == "customview") {
             $customViewId = $resultItem["id"];
             if (!$customViewId) {
                 Logger::error("custom view id missing " . var_export($resultItem, true));
                 continue;
             }
             $customViewCfg = $cfConfigMapping[$customViewId];
             if (!$customViewId) {
                 Logger::error("no custom view config for id  " . $customViewId);
                 continue;
             }
             foreach ($resultItem as $specificConfigKey => $specificConfigValue) {
                 $customViewCfg[$specificConfigKey] = $specificConfigValue;
             }
             $result[] = $customViewCfg;
         } else {
             $result[] = $resultItem;
         }
     }
     usort($result, function ($treeA, $treeB) {
         $a = $treeA["sort"] ? $treeA["sort"] : 0;
         $b = $treeB["sort"] ? $treeB["sort"] : 0;
         if ($a > $b) {
             return 1;
         } elseif ($a < $b) {
             return -1;
         } else {
             return 0;
         }
     });
     return $result;
 }