| @@ 88-128 (lines=41) @@ | ||
| 85 | $this->log('Finished sound conversion', Logger::INFO); |
|
| 86 | } |
|
| 87 | ||
| 88 | public function onChangeDownloadStateAfter (CommandEvent $event) |
|
| 89 | { |
|
| 90 | if (! $event->getCommand() instanceof ChangeDownloadState) |
|
| 91 | { |
|
| 92 | return; |
|
| 93 | } |
|
| 94 | ||
| 95 | if ($event->getCommand()->getToState() != Download::STATE_DOWNLOADING_NOT_STARTED && |
|
| 96 | $event->getCommand()->getToState() != Download::STATE_DOWNLOADING_COMPLETED) |
|
| 97 | { |
|
| 98 | return; |
|
| 99 | } |
|
| 100 | ||
| 101 | $destination = Util::realPath($this->configuration->get('sound.destination')); |
|
| 102 | if (empty($destination)) |
|
| 103 | { |
|
| 104 | return; |
|
| 105 | } |
|
| 106 | else |
|
| 107 | { |
|
| 108 | $destination = new Local($destination); |
|
| 109 | } |
|
| 110 | ||
| 111 | $this->log('Cleaning up the destination ' . $destination->getPathPrefix() . ' for sound conversion', Logger::INFO); |
|
| 112 | ||
| 113 | $directories = []; |
|
| 114 | foreach ($event->getCommand()->getDownloads() as $download) |
|
| 115 | { |
|
| 116 | $directories[basename($download->getDestination())] = basename($download->getDestination()); |
|
| 117 | } |
|
| 118 | ||
| 119 | foreach ($directories as $dirName) |
|
| 120 | { |
|
| 121 | if (! $destination->has($dirName)) |
|
| 122 | { |
|
| 123 | continue; |
|
| 124 | } |
|
| 125 | $this->log('Deleting the directory ' . $destination->applyPathPrefix($dirName)); |
|
| 126 | $destination->deleteDir($dirName); |
|
| 127 | } |
|
| 128 | } |
|
| 129 | } |
|
| 130 | ||
| @@ 176-216 (lines=41) @@ | ||
| 173 | * |
|
| 174 | * @param CommandEvent $event |
|
| 175 | */ |
|
| 176 | public function onChangeDownloadStateAfter (CommandEvent $event) |
|
| 177 | { |
|
| 178 | if (! $event->getCommand() instanceof ChangeDownloadState) |
|
| 179 | { |
|
| 180 | return; |
|
| 181 | } |
|
| 182 | ||
| 183 | if ($event->getCommand()->getToState() != Download::STATE_DOWNLOADING_COMPLETED && |
|
| 184 | $event->getCommand()->getToState() != Download::STATE_DOWNLOADING_NOT_STARTED) |
|
| 185 | { |
|
| 186 | return; |
|
| 187 | } |
|
| 188 | ||
| 189 | $destination = Util::realPath($this->configuration->get('extract.destination')); |
|
| 190 | if (! empty($destination)) |
|
| 191 | { |
|
| 192 | $destination = new Local($destination); |
|
| 193 | } |
|
| 194 | else |
|
| 195 | { |
|
| 196 | return; |
|
| 197 | } |
|
| 198 | ||
| 199 | $this->log('Cleaning up the destination ' . $destination->getPathPrefix() . ' for downloads', Logger::INFO); |
|
| 200 | ||
| 201 | $dirNames = []; |
|
| 202 | foreach ($event->getCommand()->getDownloads() as $download) |
|
| 203 | { |
|
| 204 | $dirNames[basename($download->getDestination())] = basename($download->getDestination()); |
|
| 205 | } |
|
| 206 | ||
| 207 | foreach ($dirNames as $dirName) |
|
| 208 | { |
|
| 209 | if (! $destination->has($dirName)) |
|
| 210 | { |
|
| 211 | continue; |
|
| 212 | } |
|
| 213 | $this->log('Deleting the directory ' . $destination->applyPathPrefix($dirName)); |
|
| 214 | $destination->deleteDir($dirName); |
|
| 215 | } |
|
| 216 | } |
|
| 217 | ||
| 218 | private function runCommand ($cmd, $path, $destination) |
|
| 219 | { |
|