gWorldz / get-simple-cms

Automatically exported from code.google.com/p/get-simple-cms
GNU General Public License v3.0
0 stars 0 forks source link

suggestion: new mysql setup #100

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I noticed some of the code associated with the MySQL addition to GS. I realize 
this is all new and not production quality but I want to put my advice in 
before it gets too far.

I notice alot of if type == do this which is acceptable but why not build a 
base storage class and create adapters for various engines. You wouldn't be 
limited by your storage engine of choice whether it be XML, YAML, MySQL, MSSQL 
NoSQL etc..

For example, you should just be passing arrays of data (much cleaner IMHO; more 
flexible) and have functions relative to what its doing such as:

$data = array(...);

if type == storage engine (defined in config) then
$storage = new storage_mysql();
$storage->savePost($data);

Or something of the likes just having a base storage class that accepts arrays 
that can be extended using simple php knowledge seems like a more robust path 
as the current ways could cloud up the code real fast IMHO.

I'd love to help with brainstorming on this topic.

Original issue reported on code.google.com by talkingt...@gmail.com on 12 Nov 2010 at 1:03

GoogleCodeExporter commented 9 years ago
An alternative to using classes would be to create a core set of functions and 
include only the engine required but following a set format for the functions 
within for example CSCART does something like this, where they simply include 
mysql.php driver file with same functions so that naming is never an issue and 
all you have to do is include the driver set in config:

// Returns connection ID or false on failure
function driver_db_connect($db_host, $db_user, $db_password) {
    return @mysql_connect($db_host, $db_user, $db_password);
}

// Returns connection ID or false on failure
function driver_db_select($db_name, $skip_error = false) {
    global $db_conn;
    if (@mysql_select_db($db_name, $db_conn)) {
        return $db_conn;
    }
    return false;
} 

Original comment by talkingt...@gmail.com on 12 Nov 2010 at 1:14

GoogleCodeExporter commented 9 years ago
Thanks, brainstorming help would be great. 

I completely see your point, and I think I was going more towards your second 
option with my mysql_functions.php file (only included when mysql is set as the 
type)

But i do like the storage class idea. It does look clean, and would be a great 
intro to class-based coding for GetSimple. We don't use much of it because of I 
originally didn't know it. But if we keep it simple like you suggested in your 
first comment, i say we go that way instead.

Original comment by c...@3pcmedia.com on 12 Nov 2010 at 3:39

GoogleCodeExporter commented 9 years ago
sorry, that was me - signed into my work acct. 

Original comment by ccagle8 on 12 Nov 2010 at 3:44

GoogleCodeExporter commented 9 years ago
The one issue I do have with classes is the need to do a lot of var passing. I 
believe that is why CSCART stuck with functions where they could global in 
varibles rather than passing them between classes.

I think we simply need to come up with a structured set of function names for 
say saving posts, components etc. That way we can have a document to reference 
and post on wiki for people who want to develop additional storage methods. i'm 
thinking prefix them all with a keyword to ensure we don't have issues in the 
future, maybe something like 'storage' to keep it simple (ie 
storage_save_post()).

Original comment by talkingt...@gmail.com on 12 Nov 2010 at 3:48

GoogleCodeExporter commented 9 years ago
Since we would also need load functions, im thinking storage_load_post() 
convention and the nice thing is we can keep arguments relative to the type of 
data we are needing in the above example most likely just pass a slug and then 
in xml you can have it load slug.xml and in mysql you can have it query for 
slug = slug or such depending how you are setting those tables up.

Original comment by talkingt...@gmail.com on 12 Nov 2010 at 3:53

GoogleCodeExporter commented 9 years ago
you make a good point - lets stick with the functions. i also like naming the 
functions storage_xxxxxx(). I was originally thinking of using 'database' in 
that same context, but 'storage' works better and has a wider meaning. 

Original comment by ccagle8 on 12 Nov 2010 at 6:34

GoogleCodeExporter commented 9 years ago
glad to help. i guess next thing is come up with all the core types of 
saves/loads. I think this will really clean up GS at the same time. Have all 
the XML calls in a single file will be some much easier to manage!

GS does have a wiki right?

Also, have you considered my load-ajax.php anymore?

Original comment by talkingt...@gmail.com on 12 Nov 2010 at 6:45

GoogleCodeExporter commented 9 years ago
http://code.google.com/p/get-simple-cms/source/detail?r=266

Heres a good start i think. Lets work from this as our starting point.

No Wiki yet... Matt was supposed to be looking into what software to use. It is 
high on our list of things to do. 

I will add that load-ajax for you now.... i had honestly forgot about it.

Original comment by ccagle8 on 12 Nov 2010 at 6:48

GoogleCodeExporter commented 9 years ago
Ok, let the coding begin ;)

Ah, I remember seeing something on twitter about but guess no luck yet. I 
believe most places use mediawiki.

Thanks. Think it could help some people developers in the community at some 
point.

Think we can work that editor.css autoload in with all this storage stuff?

I think after we get storage figured out we need to feature lock so many 
changes already in this upcoming version. Then start on 2.05 after the holidays 
:)

Original comment by talkingt...@gmail.com on 12 Nov 2010 at 6:59

GoogleCodeExporter commented 9 years ago
Also, looking at that revision I have a little function to help with checking 
multiple CONSTANTS, maybe you could add it to the basic helper funcs or 
something. Let me know what you think, believe it could be useful in a few 
other places too def makes readability 10x better. I'm not quite sure why PHP 
doesn't support arrays by default for defined but...also added an include_once 
just for sanity.

/** mysql */
$mysql_constants = 
array('GSSTORAGE','DB_HOST','DB_PASS','DB_USER','DB_DATABASE');
if (defined_array($mysql_constants) && lowercase(GSSTORAGE) == 'mysql') {
    include_once('mysql_functions.php');
    if (storage_connect()) {
        define('GSSAVETYPE', 'MYSQL');
    }
}

function defined_array($constants) {
    $defined = true;
    foreach ($constants as $constant) {
        if (!defined($constant)) {
            $defined = false;
            break;
        }
    }
    return $defined;
}

Original comment by talkingt...@gmail.com on 12 Nov 2010 at 7:29

GoogleCodeExporter commented 9 years ago
haha, After talking it over with Mike and Matt we think this will probably be 
3.0.0 - http://get-simple.info/start/changelog

There are too many changes for this to be a minor point release - and since we 
are introducing multi-user capable and basic mysql support - this should 
probably be a major release.

I think the feature lock will probably end at multi-user and mysql support. 
These are both huge and will help push GS way way way forward. At least these 
are what i envision as the only two MAJOR changes between now and the 3.0.0 
release.

Original comment by ccagle8 on 12 Nov 2010 at 7:29

GoogleCodeExporter commented 9 years ago
Comment #10 - loved it. 

Original comment by ccagle8 on 12 Nov 2010 at 7:44

GoogleCodeExporter commented 9 years ago
hey so I see there has been progess but I think you should further move the 
storage functions to their own folder so that people can add their own with a 
simple php file like languages. Lets say admin/storage/(xml|mysql|etc).php and 
then have a config option for the variables required for such storage engine ie 
GSSTORAGECONSTANTS

I am thinking we could then do:

if file_exists(storage/{lowercase of GSSTORAGE}.php) && 
defined_array(GSSTORAGECONSTANTS) 

include_once (storage/{lowercase of GSSTORAGE}.php)

else

include_once (storage/xml.php)

this is all just in theory not to be taken for exact code. I just think it 
opens more doors then hardcoding checks like currently is happening.

Original comment by talkingt...@gmail.com on 16 Nov 2010 at 12:34

GoogleCodeExporter commented 9 years ago
now that i think of it, constants would need to be in a comma separated format 
since you can't define arrays. so you could then do:

defined_array(explode(',',GSSTORAGECONSTANTS))

You could always add a helper to set GSSTORAGECONSTANTS for mysql, since thats 
going to be a natively supported one; just helps make it easier for users not 
using custom engine. I only suggest the use of a GSSTORAGECONSTANTS because not 
all storage engines will need all vars specially if its file based such as xml 
or yaml or even json.

Original comment by talkingt...@gmail.com on 16 Nov 2010 at 12:41

GoogleCodeExporter commented 9 years ago
i see what you are proposing, but I'm not sure I agree with it completely. I 
don't really want to introduce a new folder, but maybe i'm willing to do 
something like this though:

if file_exists(storage/{lowercase of GSSTORAGE}.php) && 
defined_array(GSSTORAGECONSTANTS) 

include_once (storage/{lowercase of GSSTORAGE}.php) 

Original comment by ccagle8 on 16 Nov 2010 at 4:22

GoogleCodeExporter commented 9 years ago
see issue 103

Original comment by ccagle8 on 31 Jan 2011 at 2:57