1515 */
1616
1717use PKP \db \DAORegistry ;
18+ use ThothApi \GraphQL \Models \Work as ThothWork ;
1819
1920import ('plugins.generic.thoth.classes.facades.ThothService ' );
2021import ('lib.pkp.classes.services.PKPSchemaService ' );
@@ -23,6 +24,8 @@ class ThothBookService
2324{
2425 public $ factory ;
2526 public $ repository ;
27+
28+ private $ originalThothBook ;
2629 private $ registeredEntryId ;
2730
2831 public function __construct ($ factory , $ repository )
@@ -31,6 +34,16 @@ public function __construct($factory, $repository)
3134 $ this ->repository = $ repository ;
3235 }
3336
37+ public function getOriginalThothBook ()
38+ {
39+ return $ this ->originalThothBook ;
40+ }
41+
42+ public function setOriginalThothBook ($ originalThothBook )
43+ {
44+ $ this ->originalThothBook = $ originalThothBook ;
45+ }
46+
3447 public function getRegisteredEntryId ()
3548 {
3649 return $ this ->registeredEntryId ;
@@ -46,6 +59,11 @@ public function register($publication, $thothImprintId)
4659 $ thothBook = $ this ->factory ->createFromPublication ($ publication );
4760 $ thothBook ->setImprintId ($ thothImprintId );
4861
62+ if ($ thothBook ->getWorkStatus () === ThothWork::WORK_STATUS_ACTIVE ) {
63+ $ this ->setOriginalThothBook ($ thothBook );
64+ $ thothBook ->setWorkStatus (ThothWork::WORK_STATUS_FORTHCOMING );
65+ }
66+
4967 $ thothBookId = $ this ->repository ->add ($ thothBook );
5068 $ publication ->setData ('thothBookId ' , $ thothBookId );
5169 $ this ->setRegisteredEntryId ($ thothBookId );
@@ -122,4 +140,16 @@ public function deleteRegisteredEntry()
122140 $ this ->repository ->delete ($ this ->getRegisteredEntryId ());
123141 $ this ->setRegisteredEntryId (null );
124142 }
143+
144+ public function setActive ()
145+ {
146+ if ($ this ->getOriginalThothBook () === null ) {
147+ return ;
148+ }
149+
150+ $ thothBook = $ this ->getOriginalThothBook ();
151+ $ thothBook ->setWorkId ($ this ->getRegisteredEntryId ());
152+ $ thothBook ->setWorkStatus (ThothWork::WORK_STATUS_ACTIVE );
153+ $ this ->repository ->edit ($ thothBook );
154+ }
125155}
0 commit comments