/** * Find a folder by path relative to \GO::config()->file_storage_path * * @param String $relpath * @param boolean $autoCreate True to auto create the folders. ACL's will be ignored. * @return Folder */ public function findByPath($relpath, $autoCreate = false, $autoCreateAttributes = array(), $caseSensitive = true) { $oldIgnoreAcl = \GO::$ignoreAclPermissions; \GO::$ignoreAclPermissions = true; $folder = false; if (substr($relpath, -1) == '/') { $relpath = substr($relpath, 0, -1); } $parts = explode('/', $relpath); $parent_id = 0; while ($folderName = array_shift($parts)) { $cacheKey = $parent_id . '/' . $folderName; if (!isset($this->_folderCache[$cacheKey])) { $col = $caseSensitive ? 't.name COLLATE utf8_bin' : 't.name'; $findParams = \GO\Base\Db\FindParams::newInstance(); $findParams->getCriteria()->addCondition('parent_id', $parent_id)->addBindParameter(':name', $folderName)->addRawCondition($col, ':name'); //use utf8_bin for case sensivitiy and special characters. $folder = $this->findSingle($findParams); if (!$folder) { if (!$autoCreate) { return false; } $folder = new Folder(); $folder->setAttributes($autoCreateAttributes); $folder->name = $folderName; $folder->parent_id = $parent_id; $folder->save(); } elseif (!empty($autoCreateAttributes)) { //should not apply it to existing folders. this leads to unexpected results. // $folder->setAttributes($autoCreateAttributes); // $folder->save(); } if (!GO::$disableModelCache) { $this->_folderCache[$cacheKey] = $folder; } } else { $folder = $this->_folderCache[$cacheKey]; } $parent_id = $folder->id; } \GO::$ignoreAclPermissions = $oldIgnoreAcl; return $folder; }