1 | <?php |
||
38 | class DavProperties extends Command { |
||
39 | |||
40 | /** |
||
41 | * @var IUserManager |
||
42 | */ |
||
43 | protected $userManager; |
||
44 | |||
45 | /** |
||
46 | * @var IDBConnection |
||
47 | */ |
||
48 | protected $connection; |
||
49 | |||
50 | /** |
||
51 | * @var ConsoleOutput |
||
52 | */ |
||
53 | protected $output; |
||
54 | |||
55 | public function __construct(IUserManager $userManager, IDBConnection $connection) { |
||
61 | |||
62 | protected function configure() { |
||
74 | |||
75 | protected function execute(InputInterface $input, OutputInterface $output) { |
||
76 | $this->output = $output; |
||
|
|||
77 | |||
78 | $this->fixDatabase(); |
||
79 | |||
80 | // Get the statements to run |
||
81 | $output->writeln("Computing the statements that need executing"); |
||
82 | $limit = $input->getOption('limit'); |
||
83 | if($limit !== 0) { |
||
84 | $output->writeln("Limiting to $limit results from DB"); |
||
85 | } |
||
86 | $statements = $this->getSqlStatements($this->connection, $limit); |
||
87 | |||
88 | // Run the statements on the DB |
||
89 | if(empty($statements)) { |
||
90 | $output->writeln("No update queries necessary"); |
||
91 | return 0; |
||
92 | } |
||
93 | $output->writeln("Executing statements on the DB"); |
||
94 | $bar = new ProgressBar($output, count($statements)); |
||
95 | foreach($statements as $s) { |
||
96 | $this->connection->executeQuery($s); |
||
97 | $bar->advance(); |
||
98 | } |
||
99 | $bar->finish(); |
||
100 | $output->writeln(""); |
||
101 | |||
102 | if($input->getOption('limit') === 0) { |
||
103 | $output->writeln("Dropping rows that are orphaned"); |
||
104 | // drop entries with empty fileid |
||
105 | $qb = $this->connection->getQueryBuilder(); |
||
106 | $dropQuery = $qb |
||
107 | ->delete('properties') |
||
108 | ->where( |
||
109 | $qb->expr()->eq('fileid', $qb->expr()->literal('0')) |
||
110 | ) |
||
111 | ->orWhere( |
||
112 | $qb->expr()->isNull('fileid') |
||
113 | ); |
||
114 | $dropQuery->execute(); |
||
115 | } |
||
116 | |||
117 | $output->writeln("Finished"); |
||
118 | |||
119 | |||
120 | } |
||
121 | |||
122 | protected function fixDatabase() { |
||
123 | $this->output->writeln("Creating the additional column on the oc_properties table"); |
||
124 | |||
125 | // Add the column |
||
126 | try { |
||
127 | $sql = "ALTER TABLE `*PREFIX*properties` ADD `fileid` BIGINT NULL"; |
||
128 | $this->connection->executeQuery($sql); |
||
129 | } catch (NonUniqueFieldNameException $e) { |
||
130 | $this->output->writeln("Column already appear to exist"); |
||
131 | } |
||
132 | |||
133 | $this->output->writeln("Adding fileid index to oc_properties table"); |
||
134 | // Add the index |
||
135 | try { |
||
136 | $sql = "CREATE INDEX fileid_index ON `*PREFIX*properties` (`fileid`)"; |
||
137 | $this->connection->executeQuery($sql); |
||
138 | } catch (DriverException $e) { |
||
139 | $this->output->writeln("Exception adding index - potentially already exists"); |
||
140 | } |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * @param IQueryBuilder $qb |
||
145 | * @param $entry |
||
146 | * @return string|null |
||
147 | */ |
||
148 | private function getRepairEntrySql(IQueryBuilder $qb, $entry) { |
||
149 | $userId = $entry['userid']; |
||
150 | $user = $this->userManager->get($userId); |
||
151 | if (!($user instanceof IUser)) { |
||
152 | return null; |
||
153 | } |
||
154 | |||
155 | // Get the user folder (sets up mounts etc) |
||
156 | $userFolder = \OC::$server->getUserFolder($userId); |
||
157 | /** @var $storage \OC\Files\Storage\Storage */ |
||
158 | $path = $userFolder->getFullPath('') . substr($entry['propertypath'], 1, strlen($entry['propertypath'])); |
||
159 | list($storage, $internalPath) = Filesystem::resolvePath($path); |
||
160 | |||
161 | $id = $storage->getCache()->getId($internalPath); |
||
162 | |||
163 | if($id !== -1) { |
||
164 | $updateQuery = $this->getRepairQuery($qb, $id, $userId, $entry['propertypath']); |
||
165 | return $updateQuery->getSQL(); |
||
166 | } |
||
167 | |||
168 | return null; |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * @param IQueryBuilder $qb |
||
173 | * @param int $fileId |
||
174 | * @param string $userId |
||
175 | * @param string $propertyPath |
||
176 | * @return IQueryBuilder |
||
177 | */ |
||
178 | private function getRepairQuery(IQueryBuilder $qb, $fileId, $userId, $propertyPath){ |
||
195 | |||
196 | /** |
||
197 | * @param IDBConnection $connection |
||
198 | * @param integer $limit |
||
199 | * @return array |
||
200 | */ |
||
201 | public function getSqlStatements(IDBConnection $connection, $limit) { |
||
255 | } |
||
256 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..