/**
     * @param string $filepath [publisher_path]/[folder]/filename.ext
     * @param MMSynchPublisherFolder $publisher
     * @param string $folder
     * @return MMSynchFile
     * @throws MMSynchException
     */
    public static function fromRoot(MMSynchPublisherFolder $publisher, $folder, $filepath)
    {
        $pos    = strpos($filepath, '/');
        $origin = substr($filepath, 0, $pos);
        $root   = $origin . '/' . $publisher->getFolder() . '/' . $folder . '/';
        $pos    = strpos($filepath, $root);

        if ($pos !== 0)
        {
            throw new MMSynchException(sprintf('File path from root "%s" not found (expected root: %s)', $filepath, $root));
        }

        $filepath = substr($filepath, $pos + strlen($root));

        return self::createFile($origin, $publisher, $folder, $filepath);
    }
示例#2
0
    public function __construct($origin, MMSynchPublisherFolder $publisher, $folder, $filename)
    {
        $this->origin = $origin;

        // Publisher part
        $this->publisherFolder = $publisher->getFolder();

        // Folder part
        $this->folder = $folder;

        // File part
        $this->fileName = $filename;

        if (substr($this->fileName, 0, 1) == '/')
            $this->fileName = substr($this->fileName, 1);

        // Full path
        $fullPathParts = array(
            MMSynchFileManager::getRootPath(),
            $this->origin,
            $this->publisherFolder,
            $this->folder,
            $this->fileName
        );

        $this->fullPath = implode('/', $fullPathParts);

        if (!is_file($this->fullPath))
        {
            $archivePath = $this->getArchivePath();

            if (is_file($archivePath))
            {
                MMSynchLog::warning(sprintf('File "%s" is archived', $this->fullPath));

                $this->fullPath = $archivePath;
                $this->archived = true;
            }
            else
            {
                throw new MMSynchException(sprintf('File "%s" not exist and is not archived', $this->fullPath));
            }
        }
    }