2323 * @license GPL 2.0 or later
2424 */
2525
26+ use XoopsModules \Wggithub ;
27+ use XoopsModules \Wggithub \Common \ {
28+ Configurator ,
29+ Migrate ,
30+ MigrateHelper
31+ };
32+
33+ /**
34+ * Prepares system prior to attempting to install module
35+ * @param \XoopsModule $module {@link XoopsModule}
36+ *
37+ * @return bool true if ready to install, false if not
38+ */
39+ function xoops_module_pre_update_wggithub (\XoopsModule $ module )
40+ {
41+ $ utility = new Wggithub \Utility ();
42+
43+ $ xoopsSuccess = $ utility ::checkVerXoops ($ module );
44+ $ phpSuccess = $ utility ::checkVerPhp ($ module );
45+
46+ return $ xoopsSuccess && $ phpSuccess ;
47+ }
48+
2649/**
2750 * @param $module
2851 * @param null $prev_version
3154 */
3255function xoops_module_update_wggithub ($ module , $ prev_version = null )
3356{
57+ require \dirname (__DIR__ ) . '/preloads/autoloader.php ' ;
58+
59+ $ moduleDirName = $ module ->dirname ();
60+
3461 //wggithub_check_db($module);
3562
3663 //check upload directory
3764 include_once __DIR__ . '/install.php ' ;
3865 xoops_module_install_wggithub ($ module );
3966
67+ // update DB corresponding to sql/mysql.sql
68+ $ configurator = new Configurator ();
69+ $ migrate = new Migrate ($ configurator );
70+
71+ $ fileSql = \XOOPS_ROOT_PATH . '/modules/ ' . $ moduleDirName . '/sql/mysql.sql ' ;
72+ // ToDo: add function setDefinitionFile to .\class\libraries\vendor\xoops\xmf\src\Database\Migrate.php
73+ // Todo: once we are using setDefinitionFile this part has to be adapted
74+ //$fileYaml = \XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/sql/update_' . $moduleDirName . '_migrate.yml';
75+ //try {
76+ //$migrate->setDefinitionFile('update_' . $moduleDirName);
77+ //} catch (\Exception $e) {
78+ // as long as this is not done default file has to be created
79+ $ moduleVersion = $ module ->getInfo ('version ' );
80+ $ fileYaml = \XOOPS_ROOT_PATH . '/modules/ ' . $ moduleDirName . "/sql/ {$ moduleDirName }_ {$ moduleVersion }_migrate.yml " ;
81+ //}
82+
83+ // create a schema file based on sql/mysql.sql
84+ $ migratehelper = new MigrateHelper ($ fileSql , $ fileYaml );
85+ if (!$ migratehelper ->createSchemaFromSqlfile ()) {
86+ \xoops_error ('Error: creation schema file failed! ' );
87+ return false ;
88+ }
89+
90+ // run standard procedure for db migration
91+ $ migrate ->synchronizeSchema ();
92+
4093 $ errors = $ module ->getErrors ();
4194 if (!empty ($ errors )) {
4295 print_r ($ errors );
@@ -51,157 +104,12 @@ function xoops_module_update_wggithub($module, $prev_version = null)
51104 *
52105 * @return bool
53106 */
107+ /*
54108function wggithub_check_db($module)
55109{
56110 $ret = true;
57111 //insert here code for database check
58112
59- // update table (add new field)
60- $ table = $ GLOBALS ['xoopsDB ' ]->prefix ('wggithub_repositories ' );
61- $ field = 'repo_release ' ;
62- $ check = $ GLOBALS ['xoopsDB ' ]->queryF ('SHOW COLUMNS FROM ` ' . $ table . "` LIKE ' " . $ field . "' " );
63- $ numRows = $ GLOBALS ['xoopsDB ' ]->getRowsNum ($ check );
64- if (!$ numRows ) {
65- $ sql = "ALTER TABLE ` $ table` ADD ` $ field` INT(1) NOT NULL DEFAULT '0' AFTER `repo_htmlurl`; " ;
66- if (!$ result = $ GLOBALS ['xoopsDB ' ]->queryF ($ sql )) {
67- xoops_error ($ GLOBALS ['xoopsDB ' ]->error () . '<br> ' . $ sql );
68- $ module ->setErrors ("Error when adding ' $ field' to table ' $ table'. " );
69- $ ret = false ;
70- }
71- }
72-
73- // update table (add new field)
74- $ table = $ GLOBALS ['xoopsDB ' ]->prefix ('wggithub_repositories ' );
75- $ field = 'repo_prerelease ' ;
76- $ check = $ GLOBALS ['xoopsDB ' ]->queryF ('SHOW COLUMNS FROM ` ' . $ table . "` LIKE ' " . $ field . "' " );
77- $ numRows = $ GLOBALS ['xoopsDB ' ]->getRowsNum ($ check );
78- if (!$ numRows ) {
79- $ sql = "ALTER TABLE ` $ table` ADD ` $ field` INT(1) NOT NULL DEFAULT '0' AFTER `repo_htmlurl`; " ;
80- if (!$ result = $ GLOBALS ['xoopsDB ' ]->queryF ($ sql )) {
81- xoops_error ($ GLOBALS ['xoopsDB ' ]->error () . '<br> ' . $ sql );
82- $ module ->setErrors ("Error when adding ' $ field' to table ' $ table'. " );
83- $ ret = false ;
84- }
85- }
86- // update table (add new field)
87- $ table = $ GLOBALS ['xoopsDB ' ]->prefix ('wggithub_repositories ' );
88- $ field = 'repo_readme ' ;
89- $ check = $ GLOBALS ['xoopsDB ' ]->queryF ('SHOW COLUMNS FROM ` ' . $ table . "` LIKE ' " . $ field . "' " );
90- $ numRows = $ GLOBALS ['xoopsDB ' ]->getRowsNum ($ check );
91- if (!$ numRows ) {
92- $ sql = "ALTER TABLE ` $ table` ADD ` $ field` INT(1) NOT NULL DEFAULT '0' AFTER `repo_htmlurl`; " ;
93- if (!$ result = $ GLOBALS ['xoopsDB ' ]->queryF ($ sql )) {
94- xoops_error ($ GLOBALS ['xoopsDB ' ]->error () . '<br> ' . $ sql );
95- $ module ->setErrors ("Error when adding ' $ field' to table ' $ table'. " );
96- $ ret = false ;
97- }
98- }
99-
100- // update table (add new field)
101- $ table = $ GLOBALS ['xoopsDB ' ]->prefix ('wggithub_directories ' );
102- $ field = 'dir_filterrelease ' ;
103- $ check = $ GLOBALS ['xoopsDB ' ]->queryF ('SHOW COLUMNS FROM ` ' . $ table . "` LIKE ' " . $ field . "' " );
104- $ numRows = $ GLOBALS ['xoopsDB ' ]->getRowsNum ($ check );
105- if (!$ numRows ) {
106- $ sql = "ALTER TABLE ` $ table` ADD ` $ field` INT(1) NOT NULL DEFAULT '0' AFTER `dir_online`; " ;
107- if (!$ result = $ GLOBALS ['xoopsDB ' ]->queryF ($ sql )) {
108- xoops_error ($ GLOBALS ['xoopsDB ' ]->error () . '<br> ' . $ sql );
109- $ module ->setErrors ("Error when adding ' $ field' to table ' $ table'. " );
110- $ ret = false ;
111- }
112- }
113-
114- // create new table
115- $ table = $ GLOBALS ['xoopsDB ' ]->prefix ('wggithub_logs ' );
116- $ check = $ GLOBALS ['xoopsDB ' ]->queryF ("SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME=' $ table' " );
117- $ numRows = $ GLOBALS ['xoopsDB ' ]->getRowsNum ($ check );
118- if (!$ numRows ) {
119- // create new table
120- $ sql = "CREATE TABLE ` $ table` (
121- `log_id` INT(8) UNSIGNED NOT NULL AUTO_INCREMENT,
122- `log_type` INT(1) NOT NULL DEFAULT '0',
123- `log_details` VARCHAR(255) NOT NULL DEFAULT '',
124- `log_result` TEXT NOT NULL ,
125- `log_datecreated` INT(11) NOT NULL DEFAULT '0',
126- `log_submitter` INT(10) NOT NULL DEFAULT '0',
127- PRIMARY KEY (`log_id`)
128- ) ENGINE=InnoDB; " ;
129- if (!$ result = $ GLOBALS ['xoopsDB ' ]->queryF ($ sql )) {
130- xoops_error ($ GLOBALS ['xoopsDB ' ]->error () . '<br> ' . $ sql );
131- $ module ->setErrors ("Error when creating table ' $ table'. " );
132- $ ret = false ;
133- }
134- }
135-
136- // update table (add new field)
137- $ table = $ GLOBALS ['xoopsDB ' ]->prefix ('wggithub_directories ' );
138- $ field = 'dir_content ' ;
139- $ check = $ GLOBALS ['xoopsDB ' ]->queryF ('SHOW COLUMNS FROM ` ' . $ table . "` LIKE ' " . $ field . "' " );
140- $ numRows = $ GLOBALS ['xoopsDB ' ]->getRowsNum ($ check );
141- if (!$ numRows ) {
142- $ sql = "ALTER TABLE ` $ table` ADD ` $ field` INT(10) NOT NULL DEFAULT '0' AFTER `dir_type`; " ;
143- if (!$ result = $ GLOBALS ['xoopsDB ' ]->queryF ($ sql )) {
144- xoops_error ($ GLOBALS ['xoopsDB ' ]->error () . '<br> ' . $ sql );
145- $ module ->setErrors ("Error when adding ' $ field' to table ' $ table'. " );
146- $ ret = false ;
147- }
148- }
149-
150- // update table (add new field)
151- $ table = $ GLOBALS ['xoopsDB ' ]->prefix ('wggithub_directories ' );
152- $ field = 'dir_descr ' ;
153- $ check = $ GLOBALS ['xoopsDB ' ]->queryF ('SHOW COLUMNS FROM ` ' . $ table . "` LIKE ' " . $ field . "' " );
154- $ numRows = $ GLOBALS ['xoopsDB ' ]->getRowsNum ($ check );
155- if (!$ numRows ) {
156- $ sql = "ALTER TABLE ` $ table` ADD ` $ field` TEXT NOT NULL AFTER `dir_type`; " ;
157- if (!$ result = $ GLOBALS ['xoopsDB ' ]->queryF ($ sql )) {
158- xoops_error ($ GLOBALS ['xoopsDB ' ]->error () . '<br> ' . $ sql );
159- $ module ->setErrors ("Error when adding ' $ field' to table ' $ table'. " );
160- $ ret = false ;
161- }
162- }
163-
164- // update table (add new field)
165- $ table = $ GLOBALS ['xoopsDB ' ]->prefix ('wggithub_readmes ' );
166- $ field = 'rm_baseurl ' ;
167- $ check = $ GLOBALS ['xoopsDB ' ]->queryF ('SHOW COLUMNS FROM ` ' . $ table . "` LIKE ' " . $ field . "' " );
168- $ numRows = $ GLOBALS ['xoopsDB ' ]->getRowsNum ($ check );
169- if (!$ numRows ) {
170- $ sql = "ALTER TABLE ` $ table` ADD ` $ field` VARCHAR(255) NOT NULL DEFAULT '' AFTER `rm_downloadurl`; " ;
171- if (!$ result = $ GLOBALS ['xoopsDB ' ]->queryF ($ sql )) {
172- xoops_error ($ GLOBALS ['xoopsDB ' ]->error () . '<br> ' . $ sql );
173- $ module ->setErrors ("Error when adding ' $ field' to table ' $ table'. " );
174- $ ret = false ;
175- }
176- }
177-
178- // update table (add new field)
179- $ table = $ GLOBALS ['xoopsDB ' ]->prefix ('wggithub_directories ' );
180- $ field = 'dir_weight ' ;
181- $ check = $ GLOBALS ['xoopsDB ' ]->queryF ('SHOW COLUMNS FROM ` ' . $ table . "` LIKE ' " . $ field . "' " );
182- $ numRows = $ GLOBALS ['xoopsDB ' ]->getRowsNum ($ check );
183- if (!$ numRows ) {
184- $ sql = "ALTER TABLE ` $ table` ADD ` $ field` INT(10) NOT NULL DEFAULT '0' AFTER `dir_filterrelease`; " ;
185- if (!$ result = $ GLOBALS ['xoopsDB ' ]->queryF ($ sql )) {
186- xoops_error ($ GLOBALS ['xoopsDB ' ]->error () . '<br> ' . $ sql );
187- $ module ->setErrors ("Error when adding ' $ field' to table ' $ table'. " );
188- $ ret = false ;
189- }
190- }
191-
192- // update table (add new field)
193- $ table = $ GLOBALS ['xoopsDB ' ]->prefix ('wggithub_repositories ' );
194- $ field = 'repo_approved ' ;
195- $ check = $ GLOBALS ['xoopsDB ' ]->queryF ('SHOW COLUMNS FROM ` ' . $ table . "` LIKE ' " . $ field . "' " );
196- $ numRows = $ GLOBALS ['xoopsDB ' ]->getRowsNum ($ check );
197- if (!$ numRows ) {
198- $ sql = "ALTER TABLE ` $ table` ADD ` $ field` INT(1) NOT NULL DEFAULT '0' AFTER `repo_release`; " ;
199- if (!$ result = $ GLOBALS ['xoopsDB ' ]->queryF ($ sql )) {
200- xoops_error ($ GLOBALS ['xoopsDB ' ]->error () . '<br> ' . $ sql );
201- $ module ->setErrors ("Error when adding ' $ field' to table ' $ table'. " );
202- $ ret = false ;
203- }
204- }
205-
206113 return $ret;
207114}
115+ */
0 commit comments