foldershare-8.x-1.2/src/Plugin/FolderShareCommand/Uncompress.php

src/Plugin/FolderShareCommand/Uncompress.php
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
81
82
83
<?php
 
namespace Drupal\foldershare\Plugin\FolderShareCommand;
 
use Drupal\foldershare\Settings;
use Drupal\foldershare\Entity\FolderShare;
 
/**
 * Defines a command plugin to unarchive (uncompress) files and folders.
 *
 * The command extracts all contents of a ZIP archive and adds them to
 * the current folder.
 *
 * Configuration parameters:
 * - 'parentId': the parent folder, if any.
 * - 'selectionIds': selected entities to Archive.
 *
 * @ingroup foldershare
 *
 * @FolderShareCommand(
 *  id              = "foldersharecommand_unarchive",
 *  label           = @Translation("Uncompress"),
 *  menuNameDefault = @Translation("Uncompress"),
 *  menuName        = @Translation("Uncompress"),
 *  description     = @Translation("Uncompress a selected ZIP file into the current location. (This command is in development and not recommended for production sites.)"),
 *  category        = "archive",
 *  weight          = 20,
 *  parentConstraints = {
 *    "kinds"   = {
 *      "rootlist",
 *      "folder",
 *    },
 *    "access"  = "create",
 *  },
 *  selectionConstraints = {
 *    "types"   = {
 *      "one",
 *    },
 *    "kinds"   = {
 *      "file",
 *    },
 *    "fileExtensions" = {
 *      "zip",
 *    },
 *    "access"  = "view",
 *  },
 * )
 */
class Uncompress extends FolderShareCommandBase {
 
  /*--------------------------------------------------------------------
   *
   * Execute.
   *
   *--------------------------------------------------------------------*/
 
  /**
   * {@inheritdoc}
   */
  public function execute() {
    $selectionIds = $this->getSelectionIds();
    $item = FolderShare::load(reset($selectionIds));
 
    try {
      $item->unarchiveFromZip();
    }
    catch (\Exception $e) {
      \Drupal::messenger()->addMessage($e->getMessage(), 'error');
    }
 
    if (Settings::getCommandNormalCompletionReportEnable() === TRUE) {
      \Drupal::messenger()->addMessage(
        t(
          "The @kind '@name' has been uncompressed.",
          [
            '@kind' => FolderShare::translateKind($item->getKind()),
            '@name' => $item->getName(),
          ]),
        'status');
    }
  }
 
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc