1 | <?php |
||
27 | class Genesis { |
||
28 | |||
29 | const DOCUMENTS_DIRNAME='/documents'; |
||
30 | |||
31 | protected $view; |
||
32 | |||
33 | protected $path; |
||
34 | |||
35 | protected $hash; |
||
36 | |||
37 | |||
38 | /** |
||
39 | * Create new genesis document |
||
40 | * @param File $file |
||
41 | * */ |
||
42 | public function __construct(File $file){ |
||
43 | $view = $file->getOwnerView(); |
||
44 | $path = $file->getPath(); |
||
45 | $owner = $file->getOwner(); |
||
46 | |||
47 | $this->view = new View('/' . $owner); |
||
48 | |||
49 | if (!$this->view->file_exists(self::DOCUMENTS_DIRNAME)){ |
||
50 | $this->view->mkdir(self::DOCUMENTS_DIRNAME ); |
||
51 | } |
||
52 | $this->validate($view, $path); |
||
53 | |||
54 | $this->hash = $view->hash('sha1', $path, false); |
||
55 | $this->path = self::DOCUMENTS_DIRNAME . '/' . $this->hash . '.odt'; |
||
56 | if (!$this->view->file_exists($this->path)){ |
||
57 | //copy new genesis to /user/documents/{hash}.odt |
||
58 | // get decrypted content |
||
59 | $content = $view->file_get_contents($path); |
||
60 | $mimetype = $view->getMimeType($path); |
||
61 | |||
62 | $data = Filter::read($content, $mimetype); |
||
63 | $this->view->file_put_contents($this->path, $data['content']); |
||
64 | } |
||
65 | |||
66 | try { |
||
67 | $this->validate($this->view, $this->path); |
||
68 | } catch (\Exception $e){ |
||
69 | throw new \Exception('Failed to copy genesis'); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | public function getPath(){ |
||
76 | |||
77 | public function getHash(){ |
||
80 | |||
81 | /** |
||
82 | * Check if genesis is valid |
||
83 | * @param \OC\Files\View $view |
||
84 | * @param string $path relative to the view |
||
85 | * @throws \Exception |
||
86 | */ |
||
87 | protected function validate($view, $path){ |
||
96 | |||
97 | } |
||
98 |