111
irmtfan
Re: SmartClone 1.10 Beta 1 ready for testing
  • 2013/5/4 1:55

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Good.
I am not completely familiar with namespace.
Also php 5.3+ is not a problem because we need a solution for module cloning (in module level not core) and new modules like newbb, xoopspoll, ... required php 5.3
but there is another issue that i think namecpace is useless for us.
I think we must add something like this in all module files to avoid name coflict in different clones:
namespace basename(basename(dirname(__FILE__)));

or better:
namespace MY_MODULE\basename(basename(dirname(__FILE__)));

but the above cannot be used. Am i miss something and am i wrong?

@zyspec:
Yes i know how SmartClone works.
I want to know if there is a way to be free of Any naming issue in module scope.
once we can do that the install and even upgrade would be as simple as renaming the modules/MODULE_DIRNAME folder.

For example we can start with your new version of XoopsPoll as a very needed module for cloning.



112
irmtfan
Re: SmartClone 1.10 Beta 1 ready for testing
  • 2013/5/3 4:07

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Is cloning possible by simple renaming of the directory?

That is the interesting question.

One of the main obstacles is function and class naming.

you have class names like
class MY_MODULE_classname extends XoopsObject
{

and it will cause issues when you have 2 blocks of the all 2 clones in one page:
Fatal errorCannot redeclare class MY_MODULE_classname


IMO if we could find a way for this cloning is possible by a simple renaming.



113
irmtfan
Re: Making a PDO "plugin" for 2.5.5 to potentially include in 2.6
  • 2013/5/3 2:40

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Quote:

it would be nice to have Criteria being able to create other type of queries besides SELECT, like INSERT, UPDATE and DELETE.

Now we have facilities for DELETE, UPDATE, INSERT in class/model
but they are general usage. (search for them and you will find)
After more investigation I think general usage is good and enough. ( but we can add some little and enhance it)
If someone like me want especial queries he can use $db but without hard-coded table.
eg in the current system you should use your object handler extended from XoopsPersistableObjectHandler:
$sql = ...
$result $this->db->query($sql$limit$start);

so the above will be executed on my object table.



114
irmtfan
Re: add some needed facilities for module developers in working with xoops database.
  • 2013/5/2 3:47

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


@redheadedrod:
You are right but please pay attention to my reasons for naming it a core bug and for requesting to add that line:
1- There are some functions in the core that you should add the prefix before using them like this:
$out func1($db->prefix("mytable"));

but there are others again in the core that you should not add the prefix before using them like this:
$out func2("mytable");

because the func2 is like this:
function func2($tablename)
{
$tablename $db->prefix($tablename);
}

So we can not blame module developers too much the core is not consistent too and the module developer have to be familiar with all of them to write correct codes

2- In many cases the module developer will received some kind of php/mysql error after adding extra prefix and can find that bad coding. but in very rare cases like this query for showing the existence of a table:

"SHOW TABLES LIKE '{$table}'"

there is not any php/mysql error. even the core logger will show you this:
SHOW TABLES LIKE my_table

because the xoops core logger will automatically sanitized the query log and will removed db prefix even if there were more than one prefix, all of them will be removed.
so again it is a bad job by the core and you can not blame the poor module developer because he didnt received any error It would be really hard for him to find that why SHOW TABLES LIKE my_table result is empty

3- While Core 2.6.0 is rather clean, core 2.5.5 and 2.5.6 is full of hard-codes and unneeded extra codes and unneeded checking. So IMO adding one line which have many benefits will not be too much for that.

4- we can add some kind of logger errors after that line to warn the module developer that he added prefix more than once
function prefix($tablename '')
    {
        if (
$tablename != '') {
    
// check if database prefix is not added yet and then add it!!!
    
if (strpos($tablename$this->prefix "_") !== 0) {
        
$tablename$this->prefix '_' $tablename;
        
$this->setLogger("DB Prefix is added");
    } else {
        
$this->setLogger("You add prefix more than once but core ignore it. Please correct your codes");
    }

            return 
$tablename;
        } else {
            return 
$this->prefix;
        }
    }
}



115
irmtfan
Re: How to write an standard module for xoops (div table, pagination , sort, order)
  • 2013/5/2 3:16

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


yes your are wrong.
// Name of the module
$modversion['name'] = _MI_PUBLISHER_MD_NAME;


is just the name of the module in user own language and be used just for displaying purposes.
so for example in english it is publisher and in persian it is پابلیشر

you can have 10 clone of the module working with one name publisher

the important part for cloning is dirname:
// Name of the directory that holds the module.
$modversion['dirname'] = basename(__DIR__);

- use basename(__DIR__) for better cloning.

Anyway, IMO the most important module that should follow this standard is TDMCreate as the xoops standard module creator.
Now it will not implement many of these standards. eg:
$modversion['dirname'] = basename(__DIR__);

edit:
Quote:

All future modules I build from scratch or redo will use this method to allow full cloning by simple renaming of the directory.

As you can see i wrote that all module developers should have a file include/common.php and put all needed definitions like this:
defined("XOOPS_ROOT_PATH") or die("XOOPS root path not defined");

define("PUBLISHER_DIRNAME"basename(dirname(__DIR__)));
define("PUBLISHER_URL"XOOPS_URL '/modules/' PUBLISHER_DIRNAME);
define("PUBLISHER_IMAGES_URL"PUBLISHER_URL '/images');
define("PUBLISHER_ADMIN_URL"PUBLISHER_URL '/admin');
define("PUBLISHER_UPLOADS_URL"XOOPS_URL '/uploads/' PUBLISHER_DIRNAME);
define("PUBLISHER_ROOT_PATH"XOOPS_ROOT_PATH '/modules/' PUBLISHER_DIRNAME);
define("PUBLISHER_UPLOADS_PATH"XOOPS_ROOT_PATH '/uploads/' PUBLISHER_DIRNAME);

xoops_loadLanguage('common'PUBLISHER_DIRNAME);

include_once 
PUBLISHER_ROOT_PATH '/include/functions.php';
include_once 
PUBLISHER_ROOT_PATH '/include/constants.php';
include_once 
PUBLISHER_ROOT_PATH '/include/seo_functions.php';
include_once 
PUBLISHER_ROOT_PATH '/class/metagen.php';
include_once 
PUBLISHER_ROOT_PATH '/class/session.php';
include_once 
PUBLISHER_ROOT_PATH '/class/publisher.php';
include_once 
PUBLISHER_ROOT_PATH '/class/request.php';

$debug false;
$publisher PublisherPublisher::getInstance($debug);

So you can use PUBLISHER_DIRNAME anywhere.
But there are other serious obstacles for cloning.
1- mysql.sql have hard-coded tables and you cannot do anything because xoops core will read it in install.

2- you have class names like
class MY_MODULE_classname extends XoopsObject
{

and it will cause issues when you have 2 blocks of the all 2 clones in one page:
Fatal errorCannot redeclare classMY_MODULE_classname in ...

There maybe other obstacles that i cannot remember. but anyway by following this standard the module will be ready for cloning.
Anyway i think this topic is not a good place to talk about cloning. it is better to continue in another topic.



116
irmtfan
Re: Position a block anywhere you want hack................
  • 2013/5/1 12:25

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


I didnt find any way to implement a nested block.
But IMO it is not good to have nested blocks.
I cannot imagine the situations doing this for my websites.
You can add that block below the other one how that it seems they are combined.



117
irmtfan
Re: How to write an standard module for xoops (div table, pagination , sort, order)
  • 2013/5/1 12:19

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Ok. today i add these about xoops_version.php to the first post:

some of them are really useful for cloning modules.
Quote:

see an example of xoops_version.php from publisher.
So we can review them one by one:
- Note: many of the following will be shown in module > about page.
// Name of the module
$modversion['name'] = _MI_PUBLISHER_MD_NAME;

- You should get the name from language file.

// Version of the module
$modversion['version'] = 1.0;


- for versioning please pay attention that xoops core can just accept this format:
VERSION = YYYY.XX
So it will ignore any version after the second number after point.
so these versions are same for xoops core:
1.011
1.014
OR:
12.126
12.129

So if your module needs an upgrade you should change the first or second number after point.

// Brief description of the module
$modversion['description'] = _MI_PUBLISHER_MD_DESC;
// Author
$modversion['author'] = "Xuups.com";
// Credits - other people but not shown in about page
$modversion['credits'] = "w4z004, hsalazar, Mithrandir, fx2024, Ackbarr, Mariuss, Marco, Michiel, phppp, outch, Xvitry, Catzwolf, Shine, McDonald, trabis, Mowaffak, Bandit-x, Shiva";
// the arg of the help url, If your module have a help file
$modversion['help']  = 'page=help';
// License
$modversion['license'] = 'GNU GPL 2.0';
$modversion['license_url'] = "www.gnu.org/licenses/gpl-2.0.html/";
// If it’s an official module = 1 but usually it is not
$modversion['official'] = 0;


// Name of the directory that holds the module.
$modversion['dirname'] = basename(__DIR__);

- use basename(__DIR__) for better cloning.

// Path and name of the module’s logo
$logo_filename $modversion['dirname'] . "_logo.png";

if (
file_exists(XOOPS_ROOT_PATH "/modules/" $modversion['dirname'] . "/images/" $logo_filename)) {
    
$modversion['image'] = "images/{$logo_filename}";
} else {
    
$modversion['image'] = "images/module_logo.png";
}

- While you could simply add your logo like this:
// Path and name of the module’s logo
$modversion['image'] = "images/mymodule_logo.png";

The above from publisher is the best way for cloning.
MORE TO COME xoops_version.php



118
irmtfan
Re: add some needed facilities for module developers in working with xoops database.
  • 2013/5/1 4:32

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Quote:
And as to the prefix statement I would think the bug is in the program that calls that routine more than once... I have done this myself but not sure it is a "bug" in the core.
yes you are totally right. but core should have the best code how that it could prevent bad coding by module developers as much as possible. because a module developer may write this more than once in his code: $db->prefix($table); So if a current core function allow adding prefix more than once without checking, I will consider it as a core bug. it can be fixed by a simple checking. Edit: @zyspec: I review your alter class more. Now i think we need these: 1- one class for alter model in class/model/alter.php 2- one class for show model in class/model/show.php 3- add required code to XoopsObject class to work with the above models. Also about your code i think: - we should decide about using FIELDS or COLUMNS - it is better to return more information in the SHOW see:
public function showFields($field null)
    {
        
$sql "SHOW FIELDS FROM {$this->table}";
        if (isset(
$field)) {
            
$sql .= " LIKE '{$field}'";
        }
        if (!
$result $this->db->queryF($sql)) {
            
xoops_error($this->db->error().'<br />'.$sql);
            return 
false;
        }
        
$ret = array();
        while (
$myrow $this->db->fetchArray($result)) {
            
$ret[$myrow["Field"]] = $myrow;
        }
        return 
$ret;
    }
- better to not use ` ` ? it will avoid mistypes. - why 2 parameters for ADD $column_type and $params. one is enough. the developer can add anything he like. eg: for add a field
MYFIEKD TINYINT100 UNSIGNED DEFAULT '0' NOT null AFTER OTHERFIELD
Your opinion?



119
irmtfan
Re: Making a PDO "plugin" for 2.5.5 to potentially include in 2.6
  • 2013/5/1 4:21

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Hi
Honestly i dont have enough php knowledge to understand your works completely.
but what Trabis wrote is amazing.
Also zyspec knows better than me.

I just want to mention something.
there should be a rule for module developers to not mentioned their module tables more than once in the whole code.

eg: if my table is mod_MUMODULE_data it just should be mentioned in my class/data.php
So it would be hard-coded anyway if you could do this if 'TableTestC' is your module table:
$result $testDB->select(sql::make()->table('TableTestC')->columns('ColumnTestC')->where($criteria3->render()));

'TableTestC' table is hard-coded.
It is bad for module cloning.
Thats why i suggested in other topic to add facilities to XoopsObejct because then module developer can get the table from handler.

Maybe something like this
[code]
$result $testDB->select(sql::make()->table()->columns('ColumnTestC')->where($criteria3->render()));

I repeat, I review your works but my php knowledge is limited.
Therefor i just reply what i understand !!!

Quote:

redheadedrod wrote:
It looks like it should be easy to add these features but I need to know just what needs to be added. There is not much sense in adding stuff that may only be used for one or two modules but if it is something that will be used by many then it makes sense to do.


You are totally right. I dont want you to add especial connector for this.
I meant i cannot add that "ON DUPLICATE KEY UPDATE" by using current class/criteria.php so it would be totally hard-coded for me.

I think we should enhance class/criteria.php how that it could get any criteria.




120
irmtfan
How to Upgrade and Downgrade a xoops module
  • 2013/5/1 2:34

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Today i wrote this for userlog. but it can be followed for any other xoops module.
Quote:

To Upgrade
==========================
1- Close your website. (highly recommended) be sure you be logged in.
2- Get a backup from your old userlog database.(all XOOPSPREFIX_mod_userlog_* tables)
3- Get a backup from your old XOOPSROOT/modules/userlog folder.
4- IF EXIST get a backup from your all old userlog custom templates in themes folder located in XOOPSROOT/themes/MY_THEME/modules/userlog. eg: XOOPSROOT/themes/default/modules/userlog
5- Go to userlog > preferences and set the module log status as Idle.
6- Delete your old userlog folder located in modules. (Do not rename it. Only delete will work and while you have the backup you should not worry about anything)
7- IF EXIST delete all old userlog custom templates in themes folder located in XOOPSROOT/themes/MY_THEME/modules/userlog. eg: XOOPSROOT/themes/default/modules/userlog
8- Upload the most recent version of userlog to XOOPSROOT/modules/userlog (upload the compressed file and decompressed via Cpanel is the best way to insure all files are correctly uploaded)
9- Go to your admin > system > modules > userlog -> update (important: wait until you see the report page. It is better to save this page for future review)
10- Go to system > maintenance > clear all caches
11- Change the default settings to your desired in the module preferences. Do not forget to back the module log status to Active.
12 - Do not forget to open your website again.

What you should not do in upgrade:
----------------------------------
- Do not install the most recent version and import the old database backup and try to update it in admin. (Do not do it in any other xoops module too otherwise it will not work correctly after upgrade)
It will not work because Xoops store other information from modules like the module version in some other tables like _modules table and you just import the module tables and not this other information.
- Do not rename the old userlog folder to something like userlog_old. because xoops system will find any folder inside modules folder and try to take it as a new module.
- Do not save your old custom template. instead try to implement your changes in templates in the new template.

To Downgrade (To Restore the old version if the upgrade goes wrong)
===================================================
1- Close your website. (highly recommended) be sure you be logged in.
2- IF YOU CAN Go to userlog > preferences and set the module log status as Idle.
3- Delete the most recent bad working userlog folder located in modules. (Do not rename it.)
4- Drop the most recent bad working userlog database. (all XOOPSPREFIX_mod_userlog_* tables)
5- IF EXIST delete all userlog custom templates in themes folder located in XOOPSROOT/themes/MY_THEME/modules/userlog. eg: XOOPSROOT/themes/default/modules/userlog
6- Upload your previous working version of userlog to XOOPSROOT/modules/userlog (upload the compressed file and decompressed via Cpanel is the best way to insure all files are correctly uploaded)
7- Import your previous working userlog database. (all XOOPSPREFIX_mod_userlog_* tables)
8- Go to your admin > system > modules > userlog -> update (important: wait until you see the report page. It is better to save this page for future review)
9- Go to system > maintenance > clear all caches
10- Change the default settings to your desired in the module preferences. Do not forget to back the module log status to Active.
11- Do not forget to open your website again.


Please pay more attention especially to this:

- Do not install the most recent version and import the old database backup and try to update it in admin. (Do not do it in any other xoops module too otherwise it will not work correctly after upgrade)
It will not work because Xoops store other information from modules like the module version in some other tables like _modules table and you just import the module tables and not this other information.




TopTop
« 1 ... 9 10 11 (12) 13 14 15 ... 284 »



Login

Who's Online

80 user(s) are online (60 user(s) are browsing Support Forums)


Members: 0


Guests: 80


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits