sfluceneplugin /lib/addon/Zend/sfLuceneDirectoryStorage.class.php

Language PHP Lines 80
MD5 Hash 33852da7ab0887debcbecc268972e262 Estimated Cost $776 (why?)
Repository https://bitbucket.org/anycode/sfluceneplugin.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/*
 * This file is part of the sfLucenePlugin package
 * (c) 2007 - 2008 Carl Vondrick <carl@carlsoft.net>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

sfLuceneToolkit::loadZend();

/**
 * symfony adapter for Zend_Search_Lucene_Storage_Directory_Filesystem to keep file
 * permissions sanes.
 * @package sfLucenePlugin
 * @subpackage Addon
 * @version SVN: $Id: sfLuceneDirectoryStorage.class.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
 */
class sfLuceneDirectoryStorage extends Zend_Search_Lucene_Storage_Directory_Filesystem
{
    public function __construct($path)
    {
      parent::__construct($path);

      sfLuceneStorageFilesystem::chmod($path, 0777);
    }

    /**
     * Creates a new, empty file in the directory with the given $filename.
     *
     * @param string $filename
     * @return Zend_Search_Lucene_Storage_File
     */
    public function createFile($filename)
    {
        if (isset($this->_fileHandlers[$filename])) {
            $this->_fileHandlers[$filename]->close();
        }
        unset($this->_fileHandlers[$filename]);
        $this->_fileHandlers[$filename] = new sfLuceneFileStorage($this->_dirPath . '/' . $filename, 'w+b');

        global $php_errormsg;
        $trackErrors = ini_get('track_errors'); ini_set('track_errors', '1');

        sfLuceneStorageFilesystem::chmod($this->_dirPath, 0777);

        ini_set('track_errors', $trackErrors);

        return $this->_fileHandlers[$filename];
    }

    /**
     * Returns a Zend_Search_Lucene_Storage_File object for a given $filename in the directory.
     *
     * If $shareHandler option is true, then file handler can be shared between File Object
     * requests. It speed-ups performance, but makes problems with file position.
     * Shared handler are good for short atomic requests.
     * Non-shared handlers are useful for stream file reading (especial for compound files).
     *
     * @param string $filename
     * @param boolean $shareHandler
     * @return Zend_Search_Lucene_Storage_File
     */
    public function getFileObject($filename, $shareHandler = true)
    {
        $fullFilename = $this->_dirPath . '/' . $filename;

        if (!$shareHandler) {
            return new sfLuceneFileStorage($fullFilename);
        }

        if (isset( $this->_fileHandlers[$filename] )) {
            $this->_fileHandlers[$filename]->seek(0);
            return $this->_fileHandlers[$filename];
        }

        $this->_fileHandlers[$filename] = new sfLuceneFileStorage($fullFilename);
        return $this->_fileHandlers[$filename];
    }
}
Back to Top