/** * generate model files */ public function run() { foreach ($this->soapClient->__getTypes() as $t) { $typeContent = $this->getTypeContent($t); if (is_array($typeContent) && isset($typeContent['content'])) { $file = SOAP_OUTPUT_BASE_DIR . '/' . SOAP_MODEL_DIR . '/' . $typeContent['class'] . '.class.php'; if (file_put_contents($file, $typeContent['content']) === false) { $this->logger->err('can not write file ' . $file . ' check if permissions are correct.'); } else { $this->logger->debug('write new model file: ' . $file); } } } }
/** * Loads a list of entries for the specicifies parameters, returns an array of Search\Backend\Data * * @return array */ public function load() { $entries = array(); $data = $this->db->fetchAll("SELECT * FROM search_backend_data" . $this->getCondition() . $this->getGroupBy() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables()); foreach ($data as $entryData) { if ($entryData['maintype'] == 'document') { $element = Document::getById($entryData['id']); } else { if ($entryData['maintype'] == 'asset') { $element = Asset::getById($entryData['id']); } else { if ($entryData['maintype'] == 'object') { $element = Object::getById($entryData['id']); } else { \Logger::err("unknown maintype "); } } } if ($element) { $entry = new Search\Backend\Data(); $entry->setId(new Search\Backend\Data\Id($element)); $entry->setFullPath($entryData['fullpath']); $entry->setType($entryData['type']); $entry->setSubtype($entryData['subtype']); $entry->setUserOwner($entryData['userowner']); $entry->setUserModification($entryData['usermodification']); $entry->setCreationDate($entryData['creationdate']); $entry->setModificationDate($entryData['modificationdate']); $entry->setPublished($entryData['published'] === 0 ? false : true); $entries[] = $entry; } } $this->model->setEntries($entries); return $entries; }
public function getGuestListAction() { try { $reponse = new Reponse(); $data = array(); if ($this->getParam("q")) { $data = $this->societe->getGuests($this->getParam("q")); } if ($data) { $reponse->message = 'TXT_GUEST_LIST'; $reponse->success = true; $reponse->data = $data; $reponse->debug = $this->getParam("q"); } else { $reponse->message = 'TXT_NO_GUEST'; $reponse->success = false; $reponse->data = $data; } $this->render($reponse); } catch (\Exception $e) { // something went wrong: eg. limit exceeded, wrong configuration, ... \Logger::err($e); echo $e->getMessage(); exit; } }
/** * * @param string $className * @param string $content */ private function writeFile($className, $content) { $file = $this->saveDir . $className . '.class.php'; if (file_put_contents($file, $content) === false) { $this->logger->err('can not write file ' . $file . ' check if permissions are correct.'); } else { $this->logger->debug('write new controller file: ' . $file); } }
public function init() { parent::init(); if (!$this->getUser()->isAllowed("plugins")) { if ($this->getUser() != null) { Logger::err("user [" . $this->getUser()->getId() . "] attempted to install plugin, but has no permission to do so."); } else { Logger::err("attempt to install plugin, but no user in session."); } } }
/** * @return void */ protected function update() { // only do this if the file exists and contains data if ($this->getDataChanged() || !$this->getCustomSetting("duration")) { try { $this->setCustomSetting("duration", $this->getDurationFromBackend()); } catch (\Exception $e) { \Logger::err("Unable to get duration of video: " . $this->getId()); } } $this->clearThumbnails(); parent::update(); }
public static function writeInfoLog($arrParam = array()) { global $postParameter; $ver = $postParameter['ver']; $appId = $postParameter['appId']; $appVer = $postParameter['appVer']; $lang = $postParameter['lang']; $logMsg = sprintf("[ver=%s][appId=%s][appVer=%s][lang=%s]", $ver, $appId, $appVer, $lang); foreach ($arrParam as $key => $value) { $logMsg .= "[{$key}={$value}]"; } Logger::err($logMsg, GAME_INFO_LOG_KEY); }
public function saveAction() { try { if ($this->getParam("id")) { $page = Document\Email::getById($this->getParam("id")); $page = $this->getLatestVersion($page); $page->setUserModification($this->getUser()->getId()); if ($this->getParam("task") == "unpublish") { $page->setPublished(false); } if ($this->getParam("task") == "publish") { $page->setPublished(true); } // only save when publish or unpublish if ($this->getParam("task") == "publish" && $page->isAllowed("publish") or $this->getParam("task") == "unpublish" && $page->isAllowed("unpublish")) { $this->setValuesToDocument($page); try { $page->save(); $this->saveToSession($page); $this->_helper->json(["success" => true]); } catch (\Exception $e) { \Logger::err($e); $this->_helper->json(["success" => false, "message" => $e->getMessage()]); } } else { if ($page->isAllowed("save")) { $this->setValuesToDocument($page); try { $page->saveVersion(); $this->saveToSession($page); $this->_helper->json(["success" => true]); } catch (\Exception $e) { if (Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) { throw $e; } \Logger::err($e); $this->_helper->json(["success" => false, "message" => $e->getMessage()]); } } } } } catch (\Exception $e) { \Logger::log($e); if (\Pimcore\Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) { $this->_helper->json(["success" => false, "type" => "ValidationException", "message" => $e->getMessage(), "stack" => $e->getTraceAsString(), "code" => $e->getCode()]); } throw $e; } $this->_helper->json(false); }
/** * */ public function mail() { $conf = Config::getSystemConfig(); if (!empty($conf->general->logrecipient)) { \Logger::debug(get_class($this) . ": detected log recipient:" . $conf->general->logrecipient); $user = User::getById($conf->general->logrecipient); \Logger::debug(get_class($this) . ": detected log recipient:" . $user->getEmail()); if ($user instanceof User && $user->isAdmin()) { $email = $user->getEmail(); \Logger::debug(get_class($this) . ": user is valid"); if (!empty($email)) { if (is_dir(PIMCORE_LOG_MAIL_TEMP)) { \Logger::debug(get_class($this) . ": detected mail log dir"); \Logger::debug(get_class($this) . ": opening dir " . PIMCORE_LOG_MAIL_TEMP); if ($handle = opendir(PIMCORE_LOG_MAIL_TEMP)) { \Logger::debug(get_class($this) . ": reading dir " . PIMCORE_LOG_MAIL_TEMP); while (false !== ($file = readdir($handle))) { \Logger::debug(get_class($this) . ": detected file " . $file); if (is_file(PIMCORE_LOG_MAIL_TEMP . "/" . $file) and is_writable(PIMCORE_LOG_MAIL_TEMP . "/" . $file)) { $now = time(); $threshold = 1 * 60 * 15; $fileModified = filemtime(PIMCORE_LOG_MAIL_TEMP . "/" . $file); \Logger::debug(get_class($this) . ": file is writeable and was last modified: " . $fileModified); if ($fileModified !== FALSE and $fileModified < $now - $threshold) { $mail = Tool::getMail(array($email), "pimcore log notification - " . $file); $mail->setIgnoreDebugMode(true); $mail->setBodyText(file_get_contents(PIMCORE_LOG_MAIL_TEMP . "/" . $file)); $mail->send(); @unlink(PIMCORE_LOG_MAIL_TEMP . "/" . $file); \Logger::debug(get_class($this) . ": sent mail and deleted temp log file " . $file); } else { if ($fileModified > $now - $threshold) { \Logger::debug(get_class($this) . ": leaving temp log file alone because file [ {$file} ] was written to within the last 15 minutes"); } } } } } } } else { \Logger::err(get_class($this) . ": Cannot send mail to configured log user [" . $user->getName() . "] because email is empty"); } } else { \Logger::err(get_class($this) . ": Cannot send mail to configured log user. User is either null or not an admin"); } } else { \Logger::debug(get_class($this) . ": No log recipient configured"); } }
public function importAction() { try { $importFile = $_FILES["Filedata"]["tmp_name"]; $routeImport = new PimPon_Routes_Import(); $routeImport->setImportFile($importFile); $routeImport->setAllowReplace($this->allowReplace()); $routeImport->doImport(); $this->_helper->json(array("success" => true, "data" => "ok"), false); } catch (Exception $ex) { Logger::err($ex->getMessage()); $this->_helper->json(array("success" => false, "data" => 'error'), false); } $this->getResponse()->setHeader("Content-Type", "text/html"); }
public function saveAction() { if ($this->getParam("id")) { $page = Document\Printpage::getById($this->getParam("id")); $page = $this->getLatestVersion($page); $page->setUserModification($this->getUser()->getId()); // save to session $key = "document_" . $this->getParam("id"); $session = new \Zend_Session_Namespace("pimcore_documents"); $session->{$key} = $page; if ($this->getParam("task") == "unpublish") { $page->setPublished(false); } if ($this->getParam("task") == "publish") { $page->setPublished(true); } // only save when publish or unpublish if ($this->getParam("task") == "publish" && $page->isAllowed("publish") or $this->getParam("task") == "unpublish" && $page->isAllowed("unpublish")) { //check, if to cleanup existing elements of document $config = Config::getWeb2PrintConfig(); if ($config->generalDocumentSaveMode == "cleanup") { $page->setElements([]); } $this->setValuesToDocument($page); try { $page->save(); $this->_helper->json(["success" => true]); } catch (\Exception $e) { \Logger::err($e); $this->_helper->json(["success" => false, "message" => $e->getMessage()]); } } else { if ($page->isAllowed("save")) { $this->setValuesToDocument($page); try { $page->saveVersion(); $this->_helper->json(["success" => true]); } catch (\Exception $e) { \Logger::err($e); $this->_helper->json(["success" => false, "message" => $e->getMessage()]); } } } } $this->_helper->json(false); }
/** * updates mockup cache, delegates creation of mockup object to tenant config * * @param $objectId * @param null $data * @return OnlineShop_Framework_ProductList_DefaultMockup */ public function saveToMockupCache($objectId, $data = null) { if (empty($data)) { $data = $this->db->fetchOne("SELECT data FROM " . $this->getStoreTableName() . " WHERE id = ? AND tenant = ?", array($objectId, $this->name)); $data = json_decode($data, true); } $mockup = $this->tenantConfig->createMockupObject($objectId, $data['data'], $data['relations']); $key = $this->createMockupCacheKey($objectId); $success = \Pimcore\Model\Cache::save(serialize($mockup), $key, [$this->getMockupCachePrefix()], null, 0, true); $result = \Pimcore\Model\Cache::load($key); if ($success && $result) { $this->db->query("UPDATE " . $this->getStoreTableName() . " SET crc_index = crc_current WHERE id = ? and tenant = ?", array($objectId, $this->name)); } else { Logger::err("Element with ID {$objectId} could not be added to mockup-cache"); } return $mockup; }
public function __construct() { $indexColumns = array(); try { $indexService = \OnlineShop_Framework_Factory::getInstance()->getIndexService(); $indexColumns = $indexService->getIndexAttributes(true); } catch (\Exception $e) { \Logger::err($e); } $options = array(); foreach ($indexColumns as $c) { $options[] = array("key" => $c, "value" => $c); } if ($this->getSpecificPriceField()) { $options[] = array("key" => \OnlineShop_Framework_IProductList::ORDERKEY_PRICE, "value" => \OnlineShop_Framework_IProductList::ORDERKEY_PRICE); } $this->setOptions($options); }
public function saveAction() { if ($this->_getParam("id")) { $page = Document_Page::getById($this->_getParam("id")); $page = $this->getLatestVersion($page); $page->getPermissionsForUser($this->getUser()); $page->setUserModification($this->getUser()->getId()); // save to session $key = "document_" . $this->_getParam("id"); $session = new Zend_Session_Namespace("pimcore_documents"); $session->{$key} = $page; if ($this->_getParam("task") == "unpublish") { $page->setPublished(false); } if ($this->_getParam("task") == "publish") { $page->setPublished(true); } // only save when publish or unpublish if ($this->_getParam("task") == "publish" && $page->isAllowed("publish") or $this->_getParam("task") == "unpublish" && $page->isAllowed("unpublish")) { $this->setValuesToDocument($page); try { $page->save(); $this->_helper->json(array("success" => true)); } catch (Exception $e) { Logger::err($e); $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } else { if ($page->isAllowed("save")) { $this->setValuesToDocument($page); try { $page->saveVersion(); $this->_helper->json(array("success" => true)); } catch (Exception $e) { Logger::err($e); $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } } } $this->_helper->json(false); }
public function getPersons() { $result = array(); try { if ($this->model->getId() > 0) { $sql = sprintf(" SELECT distinct r.src_id FROM `object_relations_4` r join object_query_4 o on o.oo_id=r.src_id WHERE r.`dest_id` = '%d' AND r.`fieldname` = 'societe' ", $this->model->getId()); $data = $this->db->FetchAll($sql); } foreach ($data as $key => $row) { $loc = \Object\Person::getById($row["src_id"]); if ($loc instanceof \Object\Person) { $result[] = $loc; } } } catch (\Exception $e) { // something went wrong: eg. limit exceeded, wrong configuration, ... \Logger::err($e); echo $e->getMessage(); } return $result; }
/** * @param $documentId * @throws \Exception */ public function startPdfGeneration($documentId) { $jobConfigFile = $this->loadJobConfigObject($documentId); $document = $this->getPrintDocument($documentId); // check if there is already a generating process running, wait if so ... Model\Tool\Lock::acquire($document->getLockKey(), 0); try { $pdf = $this->buildPdf($document, $jobConfigFile->config); file_put_contents($document->getPdfFileName(), $pdf); \Pimcore::getEventManager()->trigger("document.print.postPdfGeneration", $document, ["filename" => $document->getPdfFileName(), "pdf" => $pdf]); $creationDate = \Zend_Date::now(); $document->setLastGenerated($creationDate->get() + 1); $document->save(); } catch (\Exception $e) { $document->save(); \Logger::err($e); } Model\Tool\Lock::release($document->getLockKey()); Model\Tool\TmpStore::delete($document->getLockKey()); @unlink($this->getJobConfigFile($documentId)); }
public function saveAction() { if ($this->getParam("id")) { $page = Document\Email::getById($this->getParam("id")); $page = $this->getLatestVersion($page); $page->setUserModification($this->getUser()->getId()); if ($this->getParam("task") == "unpublish") { $page->setPublished(false); } if ($this->getParam("task") == "publish") { $page->setPublished(true); } // only save when publish or unpublish if ($this->getParam("task") == "publish" && $page->isAllowed("publish") or $this->getParam("task") == "unpublish" && $page->isAllowed("unpublish")) { $this->setValuesToDocument($page); try { $page->save(); $this->saveToSession($page); $this->_helper->json(array("success" => true)); } catch (\Exception $e) { \Logger::err($e); $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } else { if ($page->isAllowed("save")) { $this->setValuesToDocument($page); try { $page->saveVersion(); $this->saveToSession($page); $this->_helper->json(array("success" => true)); } catch (\Exception $e) { \Logger::err($e); $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } } } $this->_helper->json(false); }
public function searchAction() { if ($this->getParam("q")) { try { $page = $this->getParam('page'); if (empty($page)) { $page = 1; } $perPage = 10; $result = \Pimcore\Google\Cse::search($this->getParam("q"), ($page - 1) * $perPage, null, ["cx" => "002859715628130885299:baocppu9mii"], $this->getParam("facet")); $paginator = \Zend_Paginator::factory($result); $paginator->setCurrentPageNumber($page); $paginator->setItemCountPerPage($perPage); $this->view->paginator = $paginator; $this->view->result = $result; } catch (\Exception $e) { // something went wrong: eg. limit exceeded, wrong configuration, ... \Logger::err($e); echo $e->getMessage(); exit; } } }
protected function execute(InputInterface $input, OutputInterface $output) { // clear all data $db = \Pimcore\Db::get(); $db->query("TRUNCATE `search_backend_data`;"); $elementsPerLoop = 100; $types = array("asset", "document", "object"); foreach ($types as $type) { $listClassName = "\\Pimcore\\Model\\" . ucfirst($type) . "\\Listing"; $list = new $listClassName(); if (method_exists($list, "setUnpublished")) { $list->setUnpublished(true); } $elementsTotal = $list->getTotalCount(); for ($i = 0; $i < ceil($elementsTotal / $elementsPerLoop); $i++) { $list->setLimit($elementsPerLoop); $list->setOffset($i * $elementsPerLoop); $this->output->writeln("Processing " . $type . ": " . ($list->getOffset() + $elementsPerLoop) . "/" . $elementsTotal); $elements = $list->load(); foreach ($elements as $element) { try { $searchEntry = Search\Backend\Data::getForElement($element); if ($searchEntry instanceof Search\Backend\Data and $searchEntry->getId() instanceof Search\Backend\Data\Id) { $searchEntry->setDataFromElement($element); } else { $searchEntry = new Search\Backend\Data($element); } $searchEntry->save(); } catch (Exception $e) { \Logger::err($e); } } \Pimcore::collectGarbage(); } } $db->query("OPTIMIZE TABLE search_backend_data;"); }
public function copyAction() { $success = false; $message = ""; $sourceId = intval($this->getParam("sourceId")); $source = Object::getById($sourceId); $session = Tool\Session::get("pimcore_copy"); $targetId = intval($this->getParam("targetId")); if ($this->getParam("targetParentId")) { $sourceParent = Object::getById($this->getParam("sourceParentId")); // this is because the key can get the prefix "_copy" if the target does already exists if ($session->{$this->getParam("transactionId")}["parentId"]) { $targetParent = Object::getById($session->{$this->getParam("transactionId")}["parentId"]); } else { $targetParent = Object::getById($this->getParam("targetParentId")); } $targetPath = preg_replace("@^" . $sourceParent->getFullPath() . "@", $targetParent . "/", $source->getPath()); $target = Object::getByPath($targetPath); } else { $target = Object::getById($targetId); } if ($target->isAllowed("create")) { $source = Object::getById($sourceId); if ($source != null) { try { if ($this->getParam("type") == "child") { $newObject = $this->_objectService->copyAsChild($target, $source); $session->{$this->getParam("transactionId")}["idMapping"][(int) $source->getId()] = (int) $newObject->getId(); // this is because the key can get the prefix "_copy" if the target does already exists if ($this->getParam("saveParentId")) { $session->{$this->getParam("transactionId")}["parentId"] = $newObject->getId(); Tool\Session::writeClose(); } } elseif ($this->getParam("type") == "replace") { $this->_objectService->copyContents($target, $source); } $success = true; } catch (\Exception $e) { \Logger::err($e); $success = false; $message = $e->getMessage() . " in object " . $source->getFullPath() . " [id: " . $source->getId() . "]"; } } else { \Logger::error("could not execute copy/paste, source object with id [ {$sourceId} ] not found"); $this->_helper->json(array("success" => false, "message" => "source object not found")); } } else { \Logger::error("could not execute copy/paste because of missing permissions on target [ " . $targetId . " ]"); $this->_helper->json(array("error" => false, "message" => "missing_permission")); } $this->_helper->json(array("success" => $success, "message" => $message)); }
/** * Replaces the placeholders with the content and returns * the rendered text if a text was set with "$mail->setBodyText()" * * @return string */ public function getBodyTextRendered() { $text = $this->getBodyText(); //if the content was manually set with $obj->setBodyText(); this content will be used if ($text instanceof Zend_Mime_Part) { $rawText = $text->getRawContent(); $content = $this->placeholderObject->replacePlaceholders($rawText, $this->getParams(), $this->getDocument(), $this->getEnableLayoutOnPlaceholderRendering()); } else { //creating text version from html email if html2text is installed try { include_once "simple_html_dom.php"; include_once "html2text.php"; $htmlContent = $this->getBodyHtmlRendered(); $html = str_get_html($htmlContent); if ($html) { $body = $html->find("body", 0); if ($body) { $htmlContent = $body->innertext; } } $content = @html2text($htmlContent); } catch (Exception $e) { Logger::err($e); $content = ""; } } return $content; }
public function saveAction() { $success = false; if ($this->_getParam("id")) { $asset = Asset::getById($this->_getParam("id")); if ($asset->isAllowed("publish")) { // properties if ($this->_getParam("properties")) { $properties = array(); $propertiesData = Zend_Json::decode($this->_getParam("properties")); if (is_array($propertiesData)) { foreach ($propertiesData as $propertyName => $propertyData) { $value = $propertyData["data"]; try { $property = new Property(); $property->setType($propertyData["type"]); $property->setName($propertyName); $property->setCtype("asset"); $property->setDataFromEditmode($value); $property->setInheritable($propertyData["inheritable"]); $properties[$propertyName] = $property; } catch (Exception $e) { Logger::err("Can't add " . $propertyName . " to asset " . $asset->getFullPath()); } } $asset->setProperties($properties); } } // scheduled tasks if ($this->_getParam("scheduler")) { $tasks = array(); $tasksData = Zend_Json::decode($this->_getParam("scheduler")); if (!empty($tasksData)) { foreach ($tasksData as $taskData) { $taskData["date"] = strtotime($taskData["date"] . " " . $taskData["time"]); $task = new Schedule_Task($taskData); $tasks[] = $task; } } $asset->setScheduledTasks($tasks); } if ($this->_getParam("data")) { $asset->setData($this->_getParam("data")); } $asset->setUserModification($this->getUser()->getId()); try { $asset->save(); $asset->getData(); $success = true; } catch (Exception $e) { $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } else { Logger::debug("prevented save asset because of missing permissions "); } $this->_helper->json(array("success" => $success)); } $this->_helper->json(false); }
$elementsPerLoop = 100; $types = array("asset", "document", "object"); foreach ($types as $type) { $listClassName = "\\Pimcore\\Model\\" . ucfirst($type) . "\\Listing"; $list = new $listClassName(); if (method_exists($list, "setUnpublished")) { $list->setUnpublished(true); } $elementsTotal = $list->getTotalCount(); for ($i = 0; $i < ceil($elementsTotal / $elementsPerLoop); $i++) { $list->setLimit($elementsPerLoop); $list->setOffset($i * $elementsPerLoop); echo "Processing " . $type . ": " . ($list->getOffset() + $elementsPerLoop) . "/" . $elementsTotal . "\n"; $elements = $list->load(); foreach ($elements as $element) { try { $searchEntry = Search\Backend\Data::getForElement($element); if ($searchEntry instanceof Search\Backend\Data and $searchEntry->getId() instanceof Search\Backend\Data_Id) { $searchEntry->setDataFromElement($element); } else { $searchEntry = new Search\Backend\Data($element); } $searchEntry->save(); } catch (Exception $e) { \Logger::err($e); } } \Pimcore::collectGarbage(); } } $db->query("OPTIMIZE TABLE search_backend_data;");
public function deleteInfoAction() { $hasDependency = false; try { $document = Document::getById($this->_getParam("id")); $hasDependency = $document->getDependencies()->isRequired(); } catch (Exception $e) { Logger::err("failed to access document with id: " . $this->_getParam("id")); } $deleteJobs = array(); // check for childs if ($document instanceof Document) { $deleteJobs[] = array(array("url" => "/admin/recyclebin/add", "params" => array("type" => "document", "id" => $document->getId()))); $hasChilds = $document->hasChilds(); if (!$hasDependency) { $hasDependency = $hasChilds; } $childs = 0; if ($hasChilds) { // get amount of childs $list = new Document_List(); $list->setCondition("path LIKE '" . $document->getFullPath() . "/%'"); $childs = $list->getTotalCount(); if ($childs > 0) { $deleteObjectsPerRequest = 5; for ($i = 0; $i < ceil($childs / $deleteObjectsPerRequest); $i++) { $deleteJobs[] = array(array("url" => "/admin/document/delete", "params" => array("step" => $i, "amount" => $deleteObjectsPerRequest, "type" => "childs", "id" => $document->getId()))); } } } // the object itself is the last one $deleteJobs[] = array(array("url" => "/admin/document/delete", "params" => array("id" => $document->getId()))); } $this->_helper->json(array("hasDependencies" => $hasDependency, "childs" => $childs, "deletejobs" => $deleteJobs)); }
public function testObjectConcrete() { $client = $this->getSoapClient(); //get an object list with 3 elements $condition = "o_type='object'"; $generalCondition = $this->getListCondition(); if (!empty($generalCondition)) { if (!empty($condition)) { $condition .= " AND " . $generalCondition; } else { $condition = $generalCondition; } } $order = ""; $orderKey = ""; $offset = 0; $limit = 3; $groupBy = ""; $wsDocument = $client->getObjectList($condition, $order, $orderKey, $offset, $limit, $groupBy); $this->assertTrue(is_array($wsDocument) and $wsDocument[0] instanceof Webservice_Data_Object_List_Item); //take first element and fetch object $id = $wsDocument[0]->id; $this->assertTrue(is_numeric($id)); $wsDocument = $client->getObjectConcreteById($id); $this->assertTrue($wsDocument instanceof Webservice_Data_Object_Concrete_Out); $className = "Object_" . ucfirst($wsDocument->className); $this->assertTrue(class_exists($className)); $object = new $className(); $wsDocument->reverseMap($object); //some checks to see if we got a valid object $this->assertTrue($object->getCreationDate() > 0); $this->assertTrue(strlen($object->getPath()) > 0); //copy the object retrieved from ws $new = clone $object; $new->id = null; $new->setKey($object->getKey() . "_phpUnitTestCopy"); $new->setResource(null); //send new object back via ws $apiObject = Webservice_Data_Mapper::map($new, "Webservice_Data_Object_Concrete_In", "in"); $id = $client->createObjectConcrete($apiObject); $this->assertTrue($id > 0); $wsDocument = $client->getObjectConcreteById($id); $this->assertTrue($wsDocument instanceof Webservice_Data_Object_Concrete_Out); $refetchObject = new $className(); $wsDocument->reverseMap($refetchObject); //make sure we deal with 2 different objects $this->assertTrue($id == $refetchObject->getId()); $this->assertTrue($id != $object->getId()); //compare original object, and the one we mangled back and forth through the web service $localObject = Object_Abstract::getById($object->getId()); //remove childs, this can not be set through WS $localObject->setChilds(null); $this->assertTrue(Test_Tool::objectsAreEqual($localObject, $refetchObject, true)); //update object $refetchObject->setProperty("updateTest", "text", "a update test"); $refetchObject->setInput("my updated test"); $apiObject = Webservice_Data_Mapper::map($refetchObject, "Webservice_Data_Object_Concrete_In", "in"); // Logger::err(print_r($apiObject,true)); $success = $client->updateObjectConcrete($apiObject); Logger::err($client->getLastRequest()); $this->assertTrue($success); $id = $refetchObject->getId(); Test_Tool::resetRegistry(); $localObject = Object_Abstract::getById($id); $localObject->setChilds(null); $this->assertTrue(Test_Tool::objectsAreEqual($localObject, $refetchObject, true)); //delete our test copy $success = $client->deleteObject($refetchObject->getId()); $this->assertTrue($success); }
/** * @param null $imagePath * @return bool */ public function isVectorGraphic($imagePath = null) { if ($imagePath) { // use file-extension if filename is provided return in_array(File::getFileExtension($imagePath), ["svg", "svgz", "eps", "pdf", "ps"]); } else { try { $type = $this->resource->getimageformat(); $vectorTypes = array("EPT", "EPDF", "EPI", "EPS", "EPS2", "EPS3", "EPSF", "EPSI", "EPT", "PDF", "PFA", "PFB", "PFM", "PS", "PS2", "PS3", "SVG", "SVGZ", "MVG"); if (in_array(strtoupper($type), $vectorTypes)) { return true; } } catch (\Exception $e) { \Logger::err($e); } } return false; }
/** * Object * * @return mixed */ public function loadData() { $data = null; $zipped = false; // check both the legacy file path and the new structure foreach ([$this->getFilePath(), $this->getLegacyFilePath()] as $path) { if (file_exists($path)) { $filePath = $path; break; } if (file_exists($path . ".gz")) { $filePath = $path . ".gz"; $zipped = true; break; } } if ($zipped && is_file($filePath) && is_readable($filePath)) { $data = gzdecode(file_get_contents($filePath)); } elseif (is_file($filePath) && is_readable($filePath)) { $data = file_get_contents($filePath); } if (!$data) { \Logger::err("Version: cannot read version data from file system."); $this->delete(); return; } if ($this->getSerialized()) { $data = Serialize::unserialize($data); } if ($data instanceof Asset && file_exists($this->getBinaryFilePath())) { $binaryHandle = fopen($this->getBinaryFilePath(), "r+"); $data->setStream($binaryHandle); } elseif ($data instanceof Asset && $data->data) { // this is for backward compatibility $data->setData($data->data); } $data = Element\Service::renewReferences($data); $this->setData($data); return $data; }
/** * @param $permission * @throws \Exception */ protected function checkPermission($permission) { if (!$this->getUser() || !$this->getUser()->isAllowed($permission)) { $message = "attempt to access " . $permission . ", but has no permission to do so."; \Logger::err($message); throw new \Exception($message); } }
public static function updateMaxmindDb() { $downloadUrl = "http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz"; $geoDbFile = PIMCORE_CONFIGURATION_DIRECTORY . "/GeoLite2-City.mmdb"; $geoDbFileGz = $geoDbFile . ".gz"; $firstTuesdayOfMonth = strtotime(date("F") . " 2013 tuesday"); $filemtime = 0; if (file_exists($geoDbFile)) { $filemtime = filemtime($geoDbFile); } // update if file is older than 30 days, or if it is the first tuesday of the month if ($filemtime < time() - 30 * 86400 || date("m/d/Y") == date("m/d/Y", $firstTuesdayOfMonth) && $filemtime < time() - 86400) { $data = Tool::getHttpData($downloadUrl); if (strlen($data) > 1000000) { File::put($geoDbFileGz, $data); @unlink($geoDbFile); $sfp = gzopen($geoDbFileGz, "rb"); $fp = fopen($geoDbFile, "w"); while ($string = gzread($sfp, 4096)) { fwrite($fp, $string, strlen($string)); } gzclose($sfp); fclose($fp); unlink($geoDbFileGz); \Logger::info("Updated MaxMind GeoIP2 Database in: " . $geoDbFile); } else { \Logger::err("Failed to update MaxMind GeoIP2, size is under about 1M"); } } else { \Logger::debug("MayMind GeoIP2 Download skipped, everything up to date, last update: " . date("m/d/Y H:i", $filemtime)); } }
public function batchAction() { $success = true; try { $object = Object::getById($this->getParam("job")); if ($object) { $className = $object->getClassName(); $class = Object\ClassDefinition::getByName($className); $value = $this->getParam("value"); if ($this->getParam("valueType") == "object") { $value = \Zend_Json::decode($value); } $name = $this->getParam("name"); $parts = explode("~", $name); if (substr($name, 0, 1) == "~") { $type = $parts[1]; $field = $parts[2]; $keyid = $parts[3]; $getter = "get" . ucfirst($field); $setter = "set" . ucfirst($field); $keyValuePairs = $object->{$getter}(); if (!$keyValuePairs) { $keyValuePairs = new Object\Data\KeyValue(); $keyValuePairs->setObjectId($object->getId()); $keyValuePairs->setClass($object->getClass()); } $keyValuePairs->setPropertyWithId($keyid, $value, true); $object->{$setter}($keyValuePairs); } else { if (count($parts) > 1) { // check for bricks $brickType = $parts[0]; $brickKey = $parts[1]; $brickField = Object\Service::getFieldForBrickType($object->getClass(), $brickType); $fieldGetter = "get" . ucfirst($brickField); $brickGetter = "get" . ucfirst($brickType); $valueSetter = "set" . ucfirst($brickKey); $brick = $object->{$fieldGetter}()->{$brickGetter}(); if (empty($brick)) { $classname = "\\Pimcore\\Model\\Object\\Objectbrick\\Data\\" . ucfirst($brickType); $brickSetter = "set" . ucfirst($brickType); $brick = new $classname($object); $object->{$fieldGetter}()->{$brickSetter}($brick); } $brickClass = Object\Objectbrick\Definition::getByKey($brickType); $field = $brickClass->getFieldDefinition($brickKey); $brick->{$valueSetter}($field->getDataFromEditmode($value, $object)); } else { // everything else $field = $class->getFieldDefinition($name); if ($field) { $object->setValue($name, $field->getDataFromEditmode($value, $object)); } else { // check if it is a localized field if ($this->getParam("language")) { $localizedField = $class->getFieldDefinition("localizedfields"); if ($localizedField) { $field = $localizedField->getFieldDefinition($name); if ($field) { $object->{"set" . $name}($value, $this->getParam("language")); } } } // seems to be a system field, this is actually only possible for the "published" field yet if ($name == "published") { if ($value == "false" || empty($value)) { $object->setPublished(false); } else { $object->setPublished(true); } } } } } try { // don't check for mandatory fields here $object->setOmitMandatoryCheck(true); $object->setUserModification($this->getUser()->getId()); $object->save(); $success = true; } catch (\Exception $e) { $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } else { \Logger::debug("ObjectController::batchAction => There is no object left to update."); $this->_helper->json(array("success" => false, "message" => "ObjectController::batchAction => There is no object left to update.")); } } catch (\Exception $e) { \Logger::err($e); $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } $this->_helper->json(array("success" => $success)); }