Bläddra i källkod

Ticket #5425 - Tasks: Functionality improvements. Stage 2.

AntonLV 6 månader sedan
förälder
incheckning
a90559f13d

+ 4 - 2
modules/boonex/russian/data/langs/bx_tasks/ru.xml

@@ -102,8 +102,10 @@
 
     <string name="_bx_tasks_form_context"><![CDATA[Контекст]]></string>
     <string name="_bx_tasks_form_display_context_edit"><![CDATA[Редактировать контекст]]></string>
-    <string name="_bx_tasks_form_context_input_sys_repository"><![CDATA[Репозиторий]]></string>
-    <string name="_bx_tasks_form_context_input_repository"><![CDATA[Репозиторий]]></string>
+    <string name="_bx_tasks_form_context_input_sys_gh_username"><![CDATA[GitHub: Имя пользователя]]></string>
+    <string name="_bx_tasks_form_context_input_gh_username"><![CDATA[GitHub: Имя пользователя]]></string>
+    <string name="_bx_tasks_form_context_input_sys_gh_repository"><![CDATA[GitHub: Репозиторий]]></string>
+    <string name="_bx_tasks_form_context_input_gh_repository"><![CDATA[GitHub: Репозиторий]]></string>
     <string name="_bx_tasks_form_context_input_sys_do_submit"><![CDATA[Выполнить]]></string>
     <string name="_bx_tasks_form_context_input_do_submit"><![CDATA[Выполнить]]></string>
     <string name="_bx_tasks_form_context_input_sys_do_cancel"><![CDATA[Отменить]]></string>

+ 1 - 0
modules/boonex/tasks/classes/BxTasksConfig.php

@@ -72,6 +72,7 @@ class BxTasksConfig extends BxBaseModTextConfig
             'FIELD_STATUS_ADMIN' => 'status_admin',
             'FIELD_LABELS' => 'labels',
             'FIELD_TASKLIST' => 'tasks_list',
+            'FIELD_GH_ISSUE' => 'gh_issue',
             'FIELD_INITIAL_MEMBERS' => 'initial_members',
             'FIELD_DUE_DATE' => 'due_date',
             'FIELD_EXPIRED' => 'expired',

+ 10 - 0
modules/boonex/tasks/classes/BxTasksDb.php

@@ -55,6 +55,16 @@ class BxTasksDb extends BxBaseModTextDb
         return call_user_func_array([$this, $aMethod['name']], $aMethod['params']);
     }
 
+    public function getContextRepository($iId) 
+    {
+        $aContext = $this->getContexts([
+            'sample' => 'id', 
+            'id' => $iId
+        ]);
+
+        return $aContext && is_array($aContext) ? [$aContext['gh_username'], $aContext['gh_repository']] : false;
+    }
+
     public function getLists ($iContextId = 0)
     {
         $CNF = &$this->_oConfig->CNF;

+ 33 - 1
modules/boonex/tasks/classes/BxTasksModule.php

@@ -925,7 +925,29 @@ class BxTasksModule extends BxBaseModTextModule implements iBxDolCalendarService
     {
         return $this->_oDb->updateTimer($aSet, ['id' => (int)$iId]) !== false;
     }
-    
+
+    public function onPublished($iContentId)
+    {
+        parent::onPublished($iContentId);
+
+        $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
+        if(!$aContentInfo)
+            return;
+
+        $CNF = &$this->_oConfig->CNF;
+
+        if(($iContextId = (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) < 0) {
+            $mixedRepo = $this->_oDb->getContextRepository(abs($iContextId));
+            if($mixedRepo !== false && ($sMl = 'bx_github') && ($sMd = 'create_issue') && bx_is_srv($sMl, $sMd)) {
+                list($sGhUsername, $sGhRepository) = $mixedRepo;
+
+                $aIssue = bx_srv($sMl, $sMd, [$sGhUsername, $sGhRepository, $aContentInfo[$CNF['FIELD_TITLE']], $aContentInfo[$CNF['FIELD_TEXT']]]);
+                if($aIssue && is_array($aIssue) && ($iNumber = (int)($aIssue['number'] ?? 0)) != 0)
+                    $this->_oDb->updateEntriesBy([$CNF['FIELD_GH_ISSUE'] => $iNumber], [$CNF['FIELD_ID'] => $iContentId]);
+            }
+        }
+    }
+
     public function onExpired($iContentId)
     {
         $CNF = &$this->_oConfig->CNF;
@@ -1070,6 +1092,16 @@ class BxTasksModule extends BxBaseModTextModule implements iBxDolCalendarService
 
         $this->logActivity($iContentId, ['key' => '_bx_tasks_txt_msg_' . ($iCompleted ? '' : 'un') . 'completed']);
 
+        if(($iContextId = (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) < 0 && ($mixedRepository = $this->_oDb->getContextRepository(abs($iContextId))) !== false) {
+            $sModule = 'bx_github';
+            $sMethod = ($iCompleted ? 'close' : 'reopen') . '_issue';
+            if(bx_is_srv($sModule, $sMethod) && ($iGhIssue = (int)$aContentInfo[$CNF['FIELD_GH_ISSUE']]) != 0) {
+                list($sGhUsername, $sGhRepository) = $mixedRepository;
+
+                bx_srv($sModule, $sMethod, [$sGhUsername, $sGhRepository, $iGhIssue]);
+            }
+        }
+
         return true;
     }
 

+ 4 - 2
modules/boonex/tasks/install/langs/en.xml

@@ -102,8 +102,10 @@
 
     <string name="_bx_tasks_form_context"><![CDATA[Context]]></string>
     <string name="_bx_tasks_form_display_context_edit"><![CDATA[Edit Context]]></string>
-    <string name="_bx_tasks_form_context_input_sys_repository"><![CDATA[Repository]]></string>
-    <string name="_bx_tasks_form_context_input_repository"><![CDATA[Repository]]></string>
+    <string name="_bx_tasks_form_context_input_sys_gh_username"><![CDATA[GitHub Username]]></string>
+    <string name="_bx_tasks_form_context_input_gh_username"><![CDATA[GitHub Username]]></string>
+    <string name="_bx_tasks_form_context_input_sys_gh_repository"><![CDATA[GitHub Repository]]></string>
+    <string name="_bx_tasks_form_context_input_gh_repository"><![CDATA[GitHub Repository]]></string>
     <string name="_bx_tasks_form_context_input_sys_do_submit"><![CDATA[Submit]]></string>
     <string name="_bx_tasks_form_context_input_do_submit"><![CDATA[Submit]]></string>
     <string name="_bx_tasks_form_context_input_sys_do_cancel"><![CDATA[Cancel]]></string>

+ 11 - 7
modules/boonex/tasks/install/sql/install.sql

@@ -29,7 +29,8 @@ CREATE TABLE IF NOT EXISTS `bx_tasks_tasks` (
   `reports` int(11) NOT NULL default '0',
   `featured` int(11) NOT NULL default '0',
   `due_date` int(11) NOT NULL,
-  `tasks_list` int(11) NOT NULL,	
+  `tasks_list` int(11) NOT NULL,
+  `github_issue` int(11) NOT NULL default '0',
   `completed` tinyint(4) NOT NULL DEFAULT '0', 
   `expired` tinyint(4) NOT NULL DEFAULT '0', 
   `cf` int(11) NOT NULL default '1',
@@ -52,7 +53,8 @@ CREATE TABLE IF NOT EXISTS `bx_tasks_lists` (
 -- TABLE: contexts
 CREATE TABLE IF NOT EXISTS `bx_tasks_contexts` (
   `id` int(11) NOT NULL DEFAULT '0',
-  `repository` varchar(255) NOT NULL,
+  `gh_username` varchar(64) NOT NULL DEFAULT '',
+  `gh_repository` varchar(255) NOT NULL DEFAULT '',
   PRIMARY KEY (`id`)
 );
 
@@ -587,16 +589,18 @@ INSERT INTO `sys_form_displays` (`display_name`, `module`, `object`, `title`, `v
 ('bx_tasks_context_edit', 'bx_tasks', 'bx_tasks_context', '_bx_tasks_form_display_context_edit', 0);
 
 INSERT INTO `sys_form_inputs` (`object`, `module`, `name`, `value`, `values`, `checked`, `type`, `caption_system`, `caption`, `info`, `required`, `collapsed`, `html`, `attrs`, `attrs_tr`, `attrs_wrapper`, `checker_func`, `checker_params`, `checker_error`, `db_pass`, `db_params`, `editable`, `deletable`) VALUES
-('bx_tasks_context', 'bx_tasks', 'repository', '', '', 0, 'text', '_bx_tasks_form_context_input_sys_repository', '_bx_tasks_form_context_input_repository', '', 0, 0, 0, '', '', '', '', '', '', 'Xss', '', 0, 0),
+('bx_tasks_context', 'bx_tasks', 'gh_username', '', '', 0, 'text', '_bx_tasks_form_context_input_sys_gh_username', '_bx_tasks_form_context_input_gh_username', '', 0, 0, 0, '', '', '', '', '', '', 'Xss', '', 0, 0),
+('bx_tasks_context', 'bx_tasks', 'gh_repository', '', '', 0, 'text', '_bx_tasks_form_context_input_sys_gh_repository', '_bx_tasks_form_context_input_gh_repository', '', 0, 0, 0, '', '', '', '', '', '', 'Xss', '', 0, 0),
 ('bx_tasks_context', 'bx_tasks', 'do_submit', '_bx_tasks_form_context_input_do_submit', '', 0, 'submit', '_bx_tasks_form_context_input_sys_do_submit', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 ('bx_tasks_context', 'bx_tasks', 'do_cancel', '_bx_tasks_form_context_input_do_cancel', '', 0, 'button', '_bx_tasks_form_context_input_sys_do_cancel', '', '', 0, 0, 0, 'a:2:{s:7:"onclick";s:45:"$(''.bx-popup-applied:visible'').dolPopupHide()";s:5:"class";s:22:"bx-def-margin-sec-left";}', '', '', '', '', '', '', '', 1, 0),
 ('bx_tasks_context', 'bx_tasks', 'controls', '', 'do_submit,do_cancel', 0, 'input_set', '_bx_tasks_form_context_input_sys_controls', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0);
 
 INSERT INTO `sys_form_display_inputs` (`display_name`, `input_name`, `visible_for_levels`, `active`, `order`) VALUES
-('bx_tasks_context_edit', 'repository', 2147483647, 1, 1),
-('bx_tasks_context_edit', 'controls', 2147483647, 1, 2),
-('bx_tasks_context_edit', 'do_submit', 2147483647, 1, 3),
-('bx_tasks_context_edit', 'do_cancel', 2147483647, 1, 4);
+('bx_tasks_context_edit', 'gh_username', 2147483647, 1, 1),
+('bx_tasks_context_edit', 'gh_repository', 2147483647, 1, 2),
+('bx_tasks_context_edit', 'controls', 2147483647, 1, 3),
+('bx_tasks_context_edit', 'do_submit', 2147483647, 1, 4),
+('bx_tasks_context_edit', 'do_cancel', 2147483647, 1, 5);
 
 -- FORMS: time
 INSERT INTO `sys_objects_form` (`object`, `module`, `title`, `action`, `form_attrs`, `submit_name`, `table`, `key`, `uri`, `uri_title`, `params`, `deletable`, `active`, `override_class_name`, `override_class_file`) VALUES