}
/**
- * @inheritDoc
- */
- public function delete()
- {
- $count = parent::delete();
-
- foreach ($this->getObjects() as $style) {
- // remove custom images
- if ($style->imagePath && $style->imagePath != 'images/') {
- $this->removeDirectory($style->imagePath);
- }
-
- // remove preview image
- $previewImage = WCF_DIR . 'images/' . $style->image;
- if (\file_exists($previewImage)) {
- @\unlink($previewImage);
- }
-
- // remove stylesheet
- StyleHandler::getInstance()->resetStylesheet($style->getDecoratedObject());
- }
-
- return $count;
- }
-
- /**
- * Recursively removes a directory and all it's contents.
- *
- * @param string $pathComponent
+ * @deprecated 5.4 This method is unused.
*/
protected function removeDirectory($pathComponent)
{
*/
public function delete()
{
- parent::delete();
+ $sql = "DELETE FROM wcf1_style
+ WHERE styleID = ?";
+ $statement = WCF::getDB()->prepare($sql);
+ $statement->execute([$this->styleID]);
- // delete style files
- $files = @\glob(WCF_DIR . 'style/style-' . $this->styleID . '*.css');
- if (\is_array($files)) {
- foreach ($files as $file) {
- @\unlink($file);
- }
- }
+ // delete CSS files
+ StyleHandler::getInstance()->resetStylesheet($this->getDecoratedObject());
- // delete preload data
- @\unlink(WCF_DIR . 'style/style-' . $this->styleID . '-preload.json');
+ // remove custom images
+ if ($this->imagePath && $this->imagePath != 'images/') {
+ $this->removeDirectory($this->imagePath);
+ }
// delete preview image
if ($this->image) {
$statement->execute(['wcf.style.styleDescription' . $this->styleID]);
}
+ /**
+ * @inheritDoc
+ */
+ public static function deleteAll(array $objectIDs = [])
+ {
+ $styleList = new StyleList();
+ $styleList->decoratorClassName = static::class;
+ $styleList->setObjectIDs($objectIDs);
+ $styleList->readObjects();
+
+ foreach ($styleList as $style) {
+ \assert($style instanceof self);
+ $style->delete();
+ }
+ }
+
+ /**
+ * Recursively removes a directory and all it's contents.
+ *
+ * @since 5.4
+ */
+ private function removeDirectory(string $pathComponent)
+ {
+ $dir = WCF_DIR . $pathComponent;
+ if (\is_dir($dir)) {
+ $iterator = new \RecursiveIteratorIterator(
+ new \RecursiveDirectoryIterator($dir),
+ \RecursiveIteratorIterator::CHILD_FIRST
+ );
+ foreach ($iterator as $path) {
+ if ($path->isDir()) {
+ @\rmdir($path);
+ } else {
+ @\unlink($path);
+ }
+ }
+
+ @\rmdir($dir);
+ }
+ }
+
/**
* Sets this style as default style.
*/