Version.php 26.8 KB
Newer Older
1
<?php
2 3
namespace T3o\TerFe2\Domain\Model;

4 5
/*
 * This file is part of the TYPO3 CMS project.
6
 *
7 8 9
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
10
 *
11 12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
13
 *
14 15
 * The TYPO3 project - inspiring people to share!
 */
16

17 18
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;

19 20 21
/**
 * Single version of an extension
 */
22
class Version extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
23
{
24 25
    const VERSION_IS_INSECURE = -1;
    const VERSION_IS_OUTDATED = -2;
26 27 28

    /**
     * Title of the extension
29
     *
30 31 32
     * @var string
     * @validate NotEmpty
     */
33
    protected $title = '';
34 35 36

    /**
     * Description of the extension
37
     *
38 39
     * @var string
     */
40
    protected $description = '';
41 42 43

    /**
     * Hash of the t3x file
44
     *
45 46
     * @var string
     */
47
    protected $fileHash = '';
48 49 50

    /**
     * Author
51
     *
52
     * @var \T3o\TerFe2\Domain\Model\Author
53
     */
54
    protected $author;
55 56 57

    /**
     * The version number as integer
58
     *
59
     * @var int
60 61
     * @validate NotEmpty
     */
62
    protected $versionNumber = 0;
63 64 65

    /**
     * The version number in format "x.x.x"
66
     *
67 68 69
     * @var string
     * @validate NotEmpty
     */
70
    protected $versionString = '';
71 72 73

    /**
     * Upload date and time
74
     *
75
     * @var int
76 77
     * @validate NotEmpty
     */
78
    protected $uploadDate = 0;
79 80 81

    /**
     * The user comment for this version
82
     *
83 84
     * @var string
     */
85
    protected $uploadComment = '';
86 87 88

    /**
     * Count of downloads for this version
89
     *
90
     * @var int
91
     */
92
    protected $downloadCounter = 0;
93 94 95

    /**
     * Count of downloads for this version made in frontend
96
     *
97
     * @var int
98
     */
99
    protected $frontendDownloadCounter = 0;
100 101 102

    /**
     * State of the extension (beta, stable, obsolete, etc.)
103
     *
104 105
     * @var string
     */
106
    protected $state = '';
107 108 109

    /**
     * The category of the extension manager (frontend plugin, backend module, etc.)
110
     *
111 112
     * @var string
     */
113
    protected $emCategory = '';
114 115 116

    /**
     * Loading order in Extension Manager
117
     *
118 119
     * @var string
     */
120
    protected $loadOrder = '';
121 122 123

    /**
     * Priority
124
     *
125 126
     * @var string
     */
127
    protected $priority = '';
128 129 130

    /**
     * Information if extension is shy
131
     *
132
     * @var bool
133
     */
134
    protected $shy = false;
135 136 137

    /**
     * Internal
138
     *
139
     * @var bool
140
     */
141
    protected $internal = false;
142 143 144

    /**
     * Whether extension will be loaded in Frontend or not
145
     *
146
     * @var bool
147
     */
148
    protected $doNotLoadInFe = false;
149 150 151

    /**
     * Whether an upload folder will be created or not
152
     *
153
     * @var bool
154
     */
155
    protected $uploadfolder = false;
156 157 158

    /**
     * Whether to clear cache on load or not
159
     *
160
     * @var bool
161
     */
162
    protected $clearCacheOnLoad = false;
163 164 165

    /**
     * Module identifier
166
     *
167 168
     * @var string
     */
169
    protected $module = '';
170 171 172

    /**
     * Names of dirs to create on load
173
     *
174 175
     * @var string
     */
176
    protected $createDirs = '';
177 178 179

    /**
     * Information which existing DB tables will be modified
180
     *
181 182
     * @var string
     */
183
    protected $modifyTables = '';
184 185 186

    /**
     * Lock type
187
     *
188 189
     * @var string
     */
190
    protected $lockType = '';
191 192 193

    /**
     * CGL compliance
194
     *
195 196
     * @var string
     */
197
    protected $cglCompliance = '';
198 199 200

    /**
     * Note for the CGL compliance
201
     *
202 203
     * @var string
     */
204
    protected $cglComplianceNote = '';
205 206 207

    /**
     * Review state (-2=outdated, -1=insecure, 0=standard, 1=reviewed)
208
     *
209
     * @var int
210
     */
211
    protected $reviewState = 0;
212 213 214

    /**
     * Relation to manual object of ter_doc extension
215
     *
216 217
     * @var string
     */
218
    protected $manual = '';
219 220 221

    /**
     * Check if a manual is existing in this version
222
     *
223
     * @var bool
224
     */
225
    protected $hasManual = false;
226 227 228

    /**
     * Software relations
229
     *
230
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\T3o\TerFe2\Domain\Model\Relation>
231 232
     * @lazy
     */
233
    protected $softwareRelations;
234 235 236

    /**
     * Parent extension object
237
     *
238
     * @var \T3o\TerFe2\Domain\Model\Extension
239
     */
240
    protected $extension;
241 242 243

    /**
     * Extension provider
244
     *
245 246
     * @var string
     */
247
    protected $extensionProvider = '';
248 249 250

    /**
     * Has zip file
251
     *
252
     * @var bool
253
     */
254
    protected $hasZipFile = false;
255 256 257

    /**
     * Has images
258
     *
259
     * @var bool
260
     */
261
    protected $hasImages = false;
262 263 264

    /**
     * File size of the t3x file
265
     *
266
     * @var int
267
     */
268
    protected $t3xFileSize = 0;
269 270 271

    /**
     * File size of the zip file
272
     *
273
     * @var int
274
     */
275
    protected $zipFileSize = 0;
276

277 278 279 280 281
    /**
     * @var string
     */
    protected $composerInfo = '';

282
    /**
283
     * Constructor. Initializes all ObjectStorage instances.
284 285 286
     */
    public function __construct()
    {
287
        $this->softwareRelations = new ObjectStorage();
288 289 290 291 292 293 294
    }

    /**
     * Setter for title
     *
     * @param string $title Title of the extension
     */
295
    public function setTitle(string $title)
296 297 298 299 300 301 302 303 304
    {
        $this->title = $title;
    }

    /**
     * Getter for title
     *
     * @return string Title of the extension
     */
305
    public function getTitle(): string
306 307 308 309 310 311 312 313 314
    {
        return $this->title;
    }

    /**
     * Setter for description
     *
     * @param string $description Description of the extension
     */
315
    public function setDescription(string $description)
316 317 318 319 320 321 322 323 324
    {
        $this->description = $description;
    }

    /**
     * Getter for description
     *
     * @return string Description of the extension
     */
325
    public function getDescription(): string
326 327 328 329 330 331 332 333 334
    {
        return $this->description;
    }

    /**
     * Setter for fileHash
     *
     * @param string $fileHash Hash of the t3x file
     */
335
    public function setFileHash(string $fileHash)
336 337 338 339 340 341 342 343 344
    {
        $this->fileHash = $fileHash;
    }

    /**
     * Getter for fileHash
     *
     * @return string Hash of the t3x file
     */
345
    public function getFileHash(): string
346 347 348 349 350 351 352
    {
        return $this->fileHash;
    }

    /**
     * Setter for Author
     *
353
     * @param \T3o\TerFe2\Domain\Model\Author $author Author
354
     */
355
    public function setAuthor(Author $author)
356 357 358 359 360 361 362
    {
        $this->author = $author;
    }

    /**
     * Getter for Author
     *
363
     * @return \T3o\TerFe2\Domain\Model\Author Author
364
     */
365
    public function getAuthor()
366 367 368 369 370 371 372
    {
        return $this->author;
    }

    /**
     * Setter for versionNumber
     *
373
     * @param int $versionNumber The version number
374
     */
375
    public function setVersionNumber(int $versionNumber)
376 377 378 379 380 381 382
    {
        $this->versionNumber = $versionNumber;
    }

    /**
     * Getter for versionNumber
     *
383
     * @return int The version number
384
     */
385
    public function getVersionNumber(): int
386 387 388 389 390 391 392 393 394
    {
        return $this->versionNumber;
    }

    /**
     * Setter for versionString
     *
     * @param string $versionString The version number in format "x.x.x"
     */
395
    public function setVersionString(string $versionString)
396 397 398 399 400 401 402 403 404
    {
        $this->versionString = $versionString;
    }

    /**
     * Getter for versionString
     *
     * @return string The version number in format "x.x.x"
     */
405
    public function getVersionString(): string
406 407 408 409 410 411 412
    {
        return $this->versionString;
    }

    /**
     * Setter for uploadDate
     *
413
     * @param int $uploadDate Upload date and time
414
     */
415
    public function setUploadDate(int $uploadDate)
416 417 418 419 420 421 422
    {
        $this->uploadDate = $uploadDate;
    }

    /**
     * Getter for uploadDate
     *
423
     * @return int Upload date and time
424
     */
425
    public function getUploadDate(): int
426 427 428 429 430 431 432 433 434
    {
        return $this->uploadDate;
    }

    /**
     * Setter for uploadComment
     *
     * @param string $uploadComment The user comment for this version
     */
435
    public function setUploadComment(string $uploadComment)
436 437 438 439 440 441 442 443 444
    {
        $this->uploadComment = $uploadComment;
    }

    /**
     * Getter for uploadComment
     *
     * @return string The user comment for this version
     */
445
    public function getUploadComment(): string
446 447 448 449 450 451 452
    {
        return $this->uploadComment;
    }

    /**
     * Setter for downloadCounter
     *
453
     * @param int $downloadCounter Count of downloads
454
     */
455
    public function setDownloadCounter(int $downloadCounter)
456
    {
457
        $this->downloadCounter = $downloadCounter;
458 459 460 461 462
    }

    /**
     * Increment downloadCounter
     *
463 464
     * @param int $downloads Count of downloads
     * @param bool $frontend Downloads were made in frontend
465
     */
466
    public function incrementDownloadCounter(int $downloads = 1, bool $frontend = true)
467 468
    {
        if (!empty($frontend)) {
469
            $this->frontendDownloadCounter += $downloads;
470
        } else {
471
            $this->downloadCounter += $downloads;
472 473 474 475 476 477 478
        }
        $this->extension->recalculateDownloads();
    }

    /**
     * Getter for downloadCounter
     *
479
     * @return int Count of downloads
480
     */
481
    public function getDownloadCounter(): int
482
    {
483
        return $this->downloadCounter;
484 485 486 487 488
    }

    /**
     * Setter for frontendDownloadCounter
     *
489
     * @param int $frontendDownloadCounter Download count
490
     */
491
    public function setFrontendDownloadCounter(int $frontendDownloadCounter)
492
    {
493
        $this->frontendDownloadCounter = $frontendDownloadCounter;
494 495 496 497 498
    }

    /**
     * Getter for frontendDownloadCounter
     *
499
     * @return int Download count
500
     */
501
    public function getFrontendDownloadCounter(): int
502
    {
503
        return $this->frontendDownloadCounter;
504 505 506 507 508
    }

    /**
     * Returns all downloads
     *
509
     * @return int All downloads from external source and frontend
510
     */
511
    public function getAllDownloads(): int
512 513 514
    {
        $frontendDownloads = $this->getFrontendDownloadCounter();
        $downloads = $this->getDownloadCounter();
515

516
        return $frontendDownloads + $downloads;
517 518 519 520 521 522 523
    }

    /**
     * Setter for state
     *
     * @param string $state State of the extension (beta, stable, obsolete, etc.)
     */
524
    public function setState(string $state)
525 526 527 528 529 530 531 532 533
    {
        $this->state = $state;
    }

    /**
     * Getter for state
     *
     * @return string State of the extension (beta, stable, obsolete, etc.)
     */
534
    public function getState(): string
535 536 537 538 539 540 541 542 543
    {
        return $this->state;
    }

    /**
     * Setter for emCategory
     *
     * @param string $emCategory The category of the extension manager (frontend plugin, backend module, etc.)
     */
544
    public function setEmCategory(string $emCategory)
545 546 547 548 549 550 551 552 553
    {
        $this->emCategory = $emCategory;
    }

    /**
     * Getter for emCategory
     *
     * @return string The category of the extension manager (frontend plugin, backend module, etc.)
     */
554
    public function getEmCategory(): string
555 556 557 558 559 560 561 562 563
    {
        return $this->emCategory;
    }

    /**
     * Setter for loadOrder
     *
     * @param string $loadOrder Loading order in Extension Manager
     */
564
    public function setLoadOrder(string $loadOrder)
565 566 567 568 569 570 571 572 573
    {
        $this->loadOrder = $loadOrder;
    }

    /**
     * Getter for loadOrder
     *
     * @return string Loading order in Extension Manager
     */
574
    public function getLoadOrder(): string
575 576 577 578 579 580 581 582 583
    {
        return $this->loadOrder;
    }

    /**
     * Setter for priority
     *
     * @param string $priority Priority
     */
584
    public function setPriority(string $priority)
585 586 587 588 589 590 591 592 593
    {
        $this->priority = $priority;
    }

    /**
     * Getter for priority
     *
     * @return string Priority
     */
594
    public function getPriority(): string
595 596 597 598 599 600 601
    {
        return $this->priority;
    }

    /**
     * Setter for shy
     *
602
     * @param bool $shy Information if extension is shy
603
     */
604
    public function setShy(bool $shy)
605
    {
606
        $this->shy = $shy;
607 608 609 610 611
    }

    /**
     * Getter for shy
     *
612
     * @return bool Information if extension is shy
613
     */
614
    public function getShy(): bool
615 616 617 618 619 620 621
    {
        return $this->shy;
    }

    /**
     * Setter for internal
     *
622
     * @param bool $internal Internal
623
     */
624
    public function setInternal(bool $internal)
625
    {
626
        $this->internal = $internal;
627 628 629 630 631
    }

    /**
     * Getter for internal
     *
632
     * @return bool Internal
633
     */
634
    public function getInternal(): bool
635 636 637 638 639 640 641 642 643
    {
        return $this->internal;
    }

    /**
     * Setter for module
     *
     * @param string $module Module identifier
     */
644
    public function setModule(string $module)
645 646 647 648 649 650 651 652 653
    {
        $this->module = $module;
    }

    /**
     * Getter for module
     *
     * @return string Module identifier
     */
654
    public function getModule(): string
655 656 657 658 659 660 661
    {
        return $this->module;
    }

    /**
     * Setter for doNotLoadInFe
     *
662
     * @param bool $doNotLoadInFe Whether extension will be loaded in Frontend or not
663
     */
664
    public function setDoNotLoadInFe(bool $doNotLoadInFe)
665
    {
666
        $this->doNotLoadInFe = $doNotLoadInFe;
667 668 669 670 671
    }

    /**
     * Getter for doNotLoadInFe
     *
672
     * @return bool Whether extension will be loaded in Frontend or not
673
     */
674
    public function getDoNotLoadInFe(): bool
675 676 677 678 679 680 681
    {
        return $this->doNotLoadInFe;
    }

    /**
     * Setter for uploadfolder
     *
682
     * @param bool $uploadfolder Whether an upload folder will be created or not
683
     */
684
    public function setUploadfolder(bool $uploadfolder)
685
    {
686
        $this->uploadfolder = $uploadfolder;
687 688 689 690 691
    }

    /**
     * Getter for uploadfolder
     *
692
     * @return bool Whether an upload folder will be created or not
693
     */
694
    public function getUploadfolder(): bool
695 696 697 698 699 700 701 702 703
    {
        return $this->uploadfolder;
    }

    /**
     * Setter for createDirs
     *
     * @param string $createDirs Names of dirs to create on load
     */
704
    public function setCreateDirs(string $createDirs)
705 706 707 708 709 710 711 712 713
    {
        $this->createDirs = $createDirs;
    }

    /**
     * Getter for createDirs
     *
     * @return string Names of dirs to create on load
     */
714
    public function getCreateDirs(): string
715 716 717 718 719 720 721 722 723
    {
        return $this->createDirs;
    }

    /**
     * Setter for modifyTables
     *
     * @param string $modifyTables Information which existing DB tables will be modified
     */
724
    public function setModifyTables(string $modifyTables)
725 726 727 728 729 730 731 732 733
    {
        $this->modifyTables = $modifyTables;
    }

    /**
     * Getter for modifyTables
     *
     * @return string Information which existing DB tables will be modified
     */
734
    public function getModifyTables(): string
735 736 737 738 739 740 741
    {
        return $this->modifyTables;
    }

    /**
     * Setter for clearCacheOnLoad
     *
742
     * @param bool $clearCacheOnLoad Whether to clear cache on load or not
743
     */
744
    public function setClearCacheOnLoad(bool $clearCacheOnLoad)
745
    {
746
        $this->clearCacheOnLoad = $clearCacheOnLoad;
747 748 749 750 751
    }

    /**
     * Getter for clearCacheOnLoad
     *
752
     * @return bool Whether to clear cache on load or not
753
     */
754
    public function getClearCacheOnLoad(): bool
755 756 757 758 759 760 761 762 763
    {
        return $this->clearCacheOnLoad;
    }

    /**
     * Setter for lockType
     *
     * @param string $lockType Lock type
     */
764
    public function setLockType(string $lockType)
765 766 767 768 769 770 771 772 773
    {
        $this->lockType = $lockType;
    }

    /**
     * Getter for lockType
     *
     * @return string Lock type
     */
774
    public function getLockType(): string
775 776 777 778 779 780 781 782 783
    {
        return $this->lockType;
    }

    /**
     * Setter for cglCompliance
     *
     * @param string $cglCompliance CGL compliance
     */
784
    public function setCglCompliance(string $cglCompliance)
785 786 787 788 789 790 791 792 793
    {
        $this->cglCompliance = $cglCompliance;
    }

    /**
     * Getter for cglCompliance
     *
     * @return string CGL compliance
     */
794
    public function getCglCompliance(): string
795 796 797 798 799 800 801 802 803
    {
        return $this->cglCompliance;
    }

    /**
     * Setter for cglComplianceNote
     *
     * @param string $cglComplianceNote Note for the CGL compliance
     */
804
    public function setCglComplianceNote(string $cglComplianceNote)
805 806 807 808 809 810 811 812 813
    {
        $this->cglComplianceNote = $cglComplianceNote;
    }

    /**
     * Getter for cglComplianceNote
     *
     * @return string Note for the CGL compliance
     */
814
    public function getCglComplianceNote(): string
815 816 817 818 819 820 821
    {
        return $this->cglComplianceNote;
    }

    /**
     * Setter for reviewState
     *
822
     * @param int $reviewState Review state
823
     */
824
    public function setReviewState(int $reviewState)
825 826 827 828 829 830 831
    {
        $this->reviewState = $reviewState;
    }

    /**
     * Getter for reviewState
     *
832
     * @return int Review state
833
     */
834
    public function getReviewState(): int
835
    {
836
        return $this->reviewState;
837 838 839 840 841 842 843
    }

    /**
     * Setter for manual
     *
     * @param string $manual Relation to manual object of ter_doc extension
     */
844
    public function setManual(string $manual)
845 846 847 848 849 850 851 852 853
    {
        $this->manual = $manual;
    }

    /**
     * Getter for manual
     *
     * @return string Relation to manual object of ter_doc extension
     */
854
    public function getManual(): string
855 856 857 858 859 860 861
    {
        return $this->manual;
    }

    /**
     * Setter for has_manual
     *
862
     * @param bool $hasManual Check if version has manual
863
     */
864
    public function setHasManual(bool $hasManual)
865
    {
866
        $this->hasManual = $hasManual;
867 868 869 870 871
    }

    /**
     * Getter for has_manual
     *
872
     * @return bool $hasManual Check if version has manual
873
     */
874
    public function getHasManual(): bool
875 876 877 878 879 880 881
    {
        return $this->hasManual;
    }

    /**
     * Setter for softwareRelations
     *
882
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $softwareRelations Relations
883
     */
884
    public function setSoftwareRelations(ObjectStorage $softwareRelations)
885 886 887 888 889 890 891
    {
        $this->softwareRelations = $softwareRelations;
    }

    /**
     * Getter for softwareRelations
     *
892
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage Relations
893
     */
894
    public function getSoftwareRelations(): ObjectStorage
895 896 897 898 899 900 901 902 903
    {
        return $this->softwareRelations;
    }

    /**
     * Get filtered relations
     *
     * @return array Relations
     */
904
    public function getFilteredSoftwareRelations(): array
905 906
    {
        if (empty($this->softwareRelations)) {
907
            return [];
908 909
        }

910
        $relations = [];
911 912 913 914 915 916 917 918 919 920 921 922 923 924

        foreach ($this->softwareRelations as $relation) {
            $relationKey = $relation->getRelationKey();
            if (!empty($relationKey)) {
                $relations[] = $relation;
            }
        }

        return $relations;
    }

    /**
     * Adds a relation
     *
925
     * @param \T3o\TerFe2\Domain\Model\Relation $softwareRelation The relation to be added
926
     */
927
    public function addSoftwareRelation(Relation $softwareRelation)
928 929 930 931 932 933 934 935 936
    {
        $this->softwareRelations->attach($softwareRelation);
        // @todo implement the missing method
        //$this->buildSoftwareRelationList($this->softwareRelations);
    }

    /**
     * Removes a relation
     *
937
     * @param \T3o\TerFe2\Domain\Model\Relation $softwareRelation The relation to be removed
938
     */
939
    public function removeSoftwareRelation(Relation $softwareRelation)
940 941 942 943 944 945 946 947 948
    {
        $this->softwareRelations->detach($softwareRelation);
        // @todo implement the missing method
        // $this->buildSoftwareRelationList($this->softwareRelations);
    }

    /**
     * Returns all software relations which are conflicts
     *
949
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage $conflicts
950
     */
951
    public function getConflicts(): ObjectStorage
952
    {
953
        $conflicts = new ObjectStorage();
954
        foreach ($this->getSoftwareRelations() as $softwareRelation) {
955
            /** @var \T3o\TerFe2\Domain\Model\Relation $softwareRelation */
956 957 958 959 960
            $relationKey = $softwareRelation->getRelationKey();
            if ($softwareRelation->getRelationType() == 'conflicts' and !empty($relationKey)) {
                $conflicts->attach($softwareRelation);
            }
        }
961

962 963 964 965 966 967
        return $conflicts;
    }

    /**
     * Returns all software relations which are dependencies
     *
968
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage $dependencies
969
     */
970
    public function getDependencies(): ObjectStorage
971
    {
972
        $dependencies = new ObjectStorage();
973
        foreach ($this->getSoftwareRelations() as $softwareRelation) {
974
            /** @var \T3o\TerFe2\Domain\Model\Relation $softwareRelation */
975 976 977 978 979
            $relationKey = $softwareRelation->getRelationKey();
            if ($softwareRelation->getRelationType() == 'depends' and !empty($relationKey)) {
                $dependencies->attach($softwareRelation);
            }
        }
980

981 982 983 984 985 986
        return $dependencies;
    }

    /**
     * Setter for extension
     *
987
     * @param \T3o\TerFe2\Domain\Model\Extension $extension extension
988
     */
989
    public function setExtension(Extension $extension)
990 991 992 993 994 995 996
    {
        $this->extension = $extension;
    }

    /**
     * Getter for extension
     *
997
     * @return \T3o\TerFe2\Domain\Model\Extension extension
998
     */
999
    public function getExtension(): Extension
1000 1001 1002 1003 1004 1005 1006 1007 1008
    {
        return $this->extension;
    }

    /**
     * Setter for extensionProvider
     *
     * @param string $extensionProvider Extension Provider
     */
1009
    public function setExtensionProvider(string $extensionProvider)
1010 1011 1012 1013 1014 1015 1016 1017 1018
    {
        $this->extensionProvider = $extensionProvider;
    }

    /**
     * Getter for extensionProvider
     *
     * @return string Extension Provider
     */
1019
    public function getExtensionProvider(): string
1020 1021 1022 1023 1024 1025 1026
    {
        return $this->extensionProvider;
    }

    /**
     * Setter for hasZipFile
     *
1027
     * @param bool $hasZipFile Has zip file
1028
     */
1029
    public function setHasZipFile(bool $hasZipFile)
1030
    {
Thomas Löffler's avatar