Exemple #1
0
 /**
  * Moves a file/directory
  *
  * @param string $sourcePath
  * @param string $destinationPath
  * @return void
  */
 public function move($sourcePath, $destinationPath)
 {
     $nameParts = explode("/", $sourcePath);
     $nameParts[count($nameParts) - 1] = Pimcore_File::getValidFilename($nameParts[count($nameParts) - 1]);
     $sourcePath = implode("/", $nameParts);
     $nameParts = explode("/", $destinationPath);
     $nameParts[count($nameParts) - 1] = Pimcore_File::getValidFilename($nameParts[count($nameParts) - 1]);
     $destinationPath = implode("/", $nameParts);
     try {
         if (dirname($sourcePath) == dirname($destinationPath)) {
             try {
                 $destinationNode = $this->getNodeForPath($destinationPath);
                 // If we got here, it means the destination exists, and needs to be overwritten
                 $destinationNode->delete();
             } catch (Sabre_DAV_Exception_FileNotFound $e) {
                 // If we got here, it means the destination node does not yet exist
                 Logger::warning("Sabre_DAV_Exception_FileNotFound");
             }
             $asset = Asset::getByPath("/" . $sourcePath);
             $asset->setFilename(basename($destinationPath));
         } else {
             $asset = Asset::getByPath("/" . $sourcePath);
             $parent = Asset::getByPath("/" . dirname($destinationPath));
             $asset->setPath($parent->getFullPath() . "/");
             $asset->setParentId($parent->getId());
         }
     } catch (Exception $e) {
         Logger::error($e);
     }
     $asset->save();
 }
Exemple #2
0
 /**
  * register a new user
  */
 public function registerAction()
 {
     // init
     $status = array('success' => false, 'message' => 'register failed');
     // check data
     $list = new Object_Customer_List();
     $list->setCondition('email = ?', $this->getParam('email'));
     if ($list->count() === 1) {
         // email already exsits
         $status['message'] = 'Email already exists';
     } else {
         if ($this->getParam('password') != $this->getParam('confirm_password')) {
             // user input errors...
             $status['message'] = 'user input error...';
         } else {
             // create new user
             $user = new Object_Customer();
             $user->setFirstname($this->getParam('firstname'));
             $user->setLastname($this->getParam('lastname'));
             $user->setEmail($this->getParam('email'));
             $user->setPassword($this->getParam('password'));
             // set sys params
             $user->setParentId(10979);
             $user->setKey(Pimcore_File::getValidFilename($this->getParam('email')));
             $user->setPublished(true);
             // done
             $user->save();
             $status['success'] = true;
             $this->loginCustomer($user);
         }
     }
     // send output
     if ($this->getRequest()->isXmlHttpRequest()) {
         $this->_helper->viewRenderer->setNoRender(true);
         $this->getResponse()->setHeader('Content-Type', 'application/json');
         echo Zend_Json::encode($status);
     } else {
         if ($status['success']) {
             $this->redirect('/en/shop');
         } else {
             $this->enableLayout();
             $this->view->status = $status;
         }
     }
 }
 protected function getOrCreateAssetFolderByPath($path)
 {
     $folder = Asset_Folder::getByPath($path);
     if (!$folder instanceof Asset_Folder) {
         str_replace("\\", "/", $path);
         $parts = explode("/", $path);
         if (empty($parts[count($parts) - 1])) {
             $parts = array_slice($parts, 0, -1);
         }
         $parts = array_slice($parts, 1);
         $parentPath = "/";
         foreach ($parts as $part) {
             $parent = Asset_Folder::getByPath($parentPath);
             if ($parent instanceof Asset_Folder) {
                 $part = Pimcore_File::getValidFilename($part);
                 $folder = Asset_Folder::getByPath($parentPath . $part);
                 if (!$folder instanceof Asset_Folder) {
                     $folder = Asset::create($parent->getId(), array("filename" => $part, "type" => "folder", "userOwner" => $this->getUser()->getId(), "userModification" => $this->getUser()->getId()));
                 }
                 $parentPath .= $part . "/";
             } else {
                 Logger::error("parent not found!");
                 return null;
             }
         }
     }
     return $folder;
 }
Exemple #4
0
 /**
  * @param string $name
  * @return string
  */
 function setName($name)
 {
     $this->asset->setFilename(Pimcore_File::getValidFilename($name));
     $this->asset->save();
 }
 public function importProcessAction()
 {
     $success = true;
     $type = $this->_getParam("type");
     $parentId = $this->_getParam("parentId");
     $job = $this->_getParam("job");
     $id = $this->_getParam("id");
     $mappingRaw = Zend_Json::decode($this->_getParam("mapping"));
     $class = Object_Class::getById($this->_getParam("classId"));
     $skipFirstRow = $this->_getParam("skipHeadRow") == "true";
     $fields = $class->getFieldDefinitions();
     $file = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/import_" . $id;
     if ($type == "csv") {
         // determine type
         $dialect = Pimcore_Tool_Admin::determineCsvDialect(PIMCORE_SYSTEM_TEMP_DIRECTORY . "/import_" . $id . "_original");
         $count = 0;
         if (($handle = fopen($file, "r")) !== false) {
             $data = fgetcsv($handle, 1000, $dialect->delimiter, $dialect->quotechar, $dialect->escapechar);
         }
         if ($skipFirstRow && $job == 1) {
             //read the next row, we need to skip the head row
             $data = fgetcsv($handle, 1000, $dialect->delimiter, $dialect->quotechar, $dialect->escapechar);
         }
         $tmpFile = $file . "_tmp";
         $tmpHandle = fopen($tmpFile, "w+");
         while (!feof($handle)) {
             $buffer = fgets($handle);
             fwrite($tmpHandle, $buffer);
         }
         fclose($handle);
         fclose($tmpHandle);
         unlink($file);
         rename($tmpFile, $file);
     }
     // prepare mapping
     foreach ($mappingRaw as $map) {
         if ($map[0] !== "" && $map[1] && !empty($map[2])) {
             $mapping[$map[2]] = $map[0];
         } else {
             if ($map[1] == "published (system)") {
                 $mapping["published"] = $map[0];
             }
         }
     }
     // create new object
     $className = "Object_" . ucfirst($this->_getParam("className"));
     $parent = Object_Abstract::getById($this->_getParam("parentId"));
     $parent->getPermissionsForUser($this->getUser());
     $objectKey = "object_" . $job;
     if ($this->_getParam("filename") == "id") {
         $objectKey = null;
     } else {
         if ($this->_getParam("filename") != "default") {
             $objectKey = Pimcore_File::getValidFilename($data[$this->_getParam("filename")]);
         }
     }
     $overwrite = false;
     if ($this->_getParam("overwrite") == "true") {
         $overwrite = true;
     }
     if ($parent->isAllowed("create")) {
         $intendedPath = $parent->getFullPath() . "/" . $objectKey;
         if ($overwrite) {
             $object = Object_Abstract::getByPath($intendedPath);
             if (!$object instanceof Object_Concrete) {
                 //create new object
                 $object = new $className();
             } else {
                 if (object instanceof Object_Concrete and $object->getO_className() !== $className) {
                     //delete the old object it is of a different class
                     $object->delete();
                     $object = new $className();
                 } else {
                     if (object instanceof Object_Folder) {
                         //delete the folder
                         $object->delete();
                         $object = new $className();
                     } else {
                         //use the existing object
                     }
                 }
             }
         } else {
             $counter = 1;
             while (Object_Abstract::getByPath($intendedPath) != null) {
                 $objectKey .= "_" . $counter;
                 $intendedPath = $parent->getFullPath() . "/" . $objectKey;
                 $counter++;
             }
             $object = new $className();
         }
         $object->setClassId($this->_getParam("classId"));
         $object->setClassName($this->_getParam("className"));
         $object->setParentId($this->_getParam("parentId"));
         $object->setKey($objectKey);
         $object->setCreationDate(time());
         $object->setUserOwner($this->getUser()->getId());
         $object->setUserModification($this->getUser()->getId());
         if ($data[$mapping["published"]] === "1") {
             $object->setPublished(true);
         } else {
             $object->setPublished(false);
         }
         foreach ($class->getFieldDefinitions() as $key => $field) {
             $value = $data[$mapping[$key]];
             if (array_key_exists($key, $mapping) and $value != null) {
                 // data mapping
                 $value = $field->getFromCsvImport($value);
                 if ($value !== null) {
                     $object->setValue($key, $value);
                 }
             }
         }
         try {
             $object->save();
             $this->_helper->json(array("success" => true));
         } catch (Exception $e) {
             $this->_helper->json(array("success" => false, "message" => $object->getKey() . " - " . $e->getMessage()));
         }
     }
     $this->_helper->json(array("success" => $success));
 }
 public function getValidFilenameAction()
 {
     $this->_helper->json(array("filename" => Pimcore_File::getValidFilename($this->_getParam("value"))));
 }