Where do I start or how do I create a module for G2? With G1 I know to modify the wrappers but G2 is designed differently. From what I understand it uses XML, so theoretically I should be able to modify the XML to output the way I would like it too. But where would I start?
There is also something I am trying to figure out with the way modules and the G2 system works. Most items can be embedded or called upon from any directory on a persons website. Flash can be in Dir A and can be called and embeded into your index.php fairly easily. Most php files can be included to be embedded in. HTML can be moved around or commands can be access from another site/page instead of the typically index.php.
It was partially explained that in order to customize G2 for say a portal system, in which things are designed to embed into, or a typical site. So if your gallery is in /home/www/gallery/ but your main index is in /home/www how could they display and access the gallery there without having to have the gallery installed in the root directory?
Is there going to be a way to call upon the G2 gallery embeded into a website? Or will it have to be done by creating a module for it that looks and feels like your website then putting it into G2 (which was in a way the way it was setup, had to modify wrappers in order to make it look like a website)?
Posts: 115
I either need more documentation, or smaller examples; because the module system does not seem straight forward to me yet.
But here's the current documentation:
http://gallery.menalto.com/modules.php?op=modload&name=GalleryDocs&file=index&page=gallery2-devguide.modules.php
Joseph Elwell.
Posts: 181
I went through that an feel completely lost. I'm sure once I get the hang of it I can understand but to me its completely alien at the moment.
Posts: 8601
First you need to decide what you want to build.. there are 3 main choices:
- CSS appearance: build a Theme
- How items (albums, photos, etc) are displayed: build a Layout
- New functionality: build a Module
Also, if you just want to add some content around G2 (site header or something) you can make a templates/global.tpl.local file.
To understand things better it really helps to look at existing code while reading the documentation mentioned above. The comments module is a good one to examine.. try looking at the getItemLinks() method in module.inc and see how that leads to links in the <Item Actions> picklist; they invoke loadTemplate in ShowComments.inc or AddComment.inc; those return the smarty template to render the page (in the templates dir). In the .tpl files you can see how they reference data that was loaded into the $template in the .inc file.
Hope this helps a little bit...
Posts: 181
Ok I don't really need to build a theme, just yet. The layout is fine for a little bit longer. So I guess it would fit under a module. Essentially I use a portal system called MK Portal. It has a header, footer and a left/right column which are collapsable. I want to be able to have a link from it to albums within the gallery but have the gallery embedded within the page so the users keep a common look through the site and also have access to the left/right column menus. You can see more by what I mean at my site here:
http://www.protoculturex.com/
I tried using a php include with G1, which we know doesn't work. We have to build the site around the actual wrappers of G1 for it to work properly. Since I can't build the portal around it that didn't work. I've jury rigged things with an IFrame which you can see here. The only problem is because of the way IFrame works it has to have a set height, so if the main page height is set to 900 and I go into an album which only has a height of 400, then I have large blank white space beneath the pictures. So it looks unprofessional and sloppy.
With that in mind, what would be the best way to try to integrate them?
Posts: 8601
Valiant or others can give you more tips on embedding.. I haven't tried that myself. One thing that may give you some ideas is how external image block works.. look at the bottom of the Site Admin page for Image Block module, and look at modules/imageblock/External.inc
Posts: 7994
Portal integration is the toughest kind of integration since you want to blend G2 seamlessly into the portal. We've designed G2 such that it has several convenient choke points to make this process much easier, however we'll have to do some work for each individual integration to get it going properly. Thus far we have not yet done any CMS integrations so there are bound to be a few gotchas ahead. We've been waiting for the product to get to a more mature stage first.
There are two ways to do the integration. One way is that you modify G2 to include callbacks to the portal. The other way is to use the portal's module concept to wrap G2 and include it. I'm not familiar with MK Portal so I don't know if they have the concept of pluggable modules or not. I checked out their websitte and it's unclear to me what they're running, but it looks vaguely Nuke like to me.
The best approach is to have the portal include G2 as a module. You can achieve much of this by simply creating a minimalist MK module that includes G2's main.php. Then modify templates/global.tpl.local to strip away the extra XHTML that sets it up to be a standalone page and just keep the main content which is inside the <body> block. Obviously some knowledge of MK modules is required here, but if they've done their job right it shouldn't be that hard.
That will get you to the point where you can view one G2 page inside your MK portal as. The next step will be to modify modules/core/classes/GalleryUrlGenerator so that all the urls that G2 creates are generated such that they lead back to the MK Portal and tell it to delegate to the G2 module. Now you'll be able to navigate your G2 inside the MK Portal.
After that, we'll need to make changes to the session code so that we bind tightly to the MK Portal session, and then we'll need to make some changes so that we can use the MK Portal database for user and group information. We can talk about that stuff when you get farther along.
After we do a few CMS integrations, we can refactor the core code so that the integrations can all be done from within a module. But let's do a few by hand first so that we can get the lay of the land.
Posts: 181
OK so far I've done the easy part of creating a module and placing it inside MK Portal. The best part is that it works, at least displaying the main.php page. You can see it here. So far that was easy, I remember G1 having problems with include so its nice to see that part working at least.
Inside modules/core/classes/GalleryUrlGenerator do I modify this:
From the instructions if I understand correctly it says, Return the current URL's directory. Eg, if the url is: http://example.com/gallery2/main.php. Then we return: http://example.com/gallery2/. So does that mean I would modify like this:
I'm not exactly sure what you mean by modifying and stripping out the extra XHTML that makes it a standalone page unless you mean remove all the stuff in here:
Also if MK Portal uses Nuke, does that mean that modules for other Nuke based portals/forums/etc could essentially use the same module? If they can I'll save, document, screenshot everything as clear as possible so that others have a better visual idea.
Posts: 32509
I'm trying to integrate G2 as a module in xaraya as I plan to create my next site with xaraya. I didn't know how to write a module a for xaraya that's why it takes a little bit longer.
But I'm sure I can profit from your first steps.
Your visually integrated page still has the <html><title>....<body> tags from G2.
There are 20/21 files in G2 having <body> or <html> tags: layouts, templates, files in lib, install, etc.
Do we have to edit most of these files?
We need to get the <head> and <title> variables to send it to the portal templates.
Posts: 181
Ok I removed the html, body tags from global.tpl. I hope that was correct. It looked like the link to the css was lib/IE7/ie7-html.css so I tried including a direct link to it with the MK Portal items that didn't seem to work by doing the direct link to it http://www.protoculturex.com/temp/lib/IE7/ie7-html.css. Is there a list of the .css used in G2? I can then manually add those manually to the portal .css?
Posts: 7994
So far, so good.
getCurrentUrlDir() should return the url to the G2 base dir, which in your case is http://www.protoculturex.com/temp/ for now.
The main thing that you need to do is to change generateUrl() so that urls that would normally look like this:
Look like this instead:
http://www.protoculturex.com/index.php?ind=testing&g2_view=members:MembersList
I think you can change this block:
to this:
to get the desired effect. Obviously hardcoding it is a shortcut, but let's get it working first then refine it.
I wouldn't worry too much about documenting it. However, when this is done what would be really helpful is if you could send me a diff of all the changes you've made (at least the ones that we've discussed) so that I can get an idea of how much we had to change things around. That will make it easier for me to refactor the changes out into a module.
Posts: 7994
Nope. You should only have to edit the files in the global template directory, otherwise we're screwing something up.
We've got that information, but I'm sure that every portal has its own way of accepting it. Everything that we want to put into the <head> block comes from this smarty block:
So we just need to figure out how Xaraya, et al wants that data digested.
Posts: 7994
instead of modifying global.tl, you should copy it to global.tpl.local and modify that instead. Otherwise when you upgrade, global.tpl will get overwritten. G2 will grab global.tpl.local if it's there and use that instead.
We're considering losing the IE7 layer because it's causing IE6 to crash for one of our developers so I wouldn't worry about that for now.
Finally, you should create your own theme (copy the matrix theme and modify it -- don't forget to change the class name inside theme.inc appropriately) which is similar to your MK Portal theme so that it's seamless.
I think that we'll eventually provide a dynamic theme that can suck settings from the portal's current theme, but I haven't figured out the best way to do that yet so for now I think we'll have to hardcode it.
Posts: 181
Inside GalleryUrlGenerator.class I found:
and replaced it with:
I then put the original global.tpl back in and uploaded my modified one, now named global.tpl.local. I completely removed everything in the <head tags and the whole <body tag. Was there anything in there that I should of kept or would have to be moved?
I am not sure I completely understood what you meant by creating a new theme, so I hope this is correct. I created a new theme folder, called it mkportal. I then modified theme.inc and changed where it said Matrix to Mkportal.
The images no longer are displayed, most likely because I changed the GenerateUrl like said above. If I right click on it and click properties the following is the shown link:
and when I click on an image I get the following errors:
Posts: 32509
Could you please tell me in what variable in main.php or with which method I get this data from G2?
I need all data that is part of the <head> <tile><meta name="description"> etc. section and the <body tags "onLoad" etc.
If there's no API to get these values, I'll have to parse the resulting HTML
of G2 for the <head> section.
Sidenote: If there's no API in G2 for get/set <meta name="keywords"> and meta name="description"> you'll have to code it anyway as search engines (google, ...) will profit from HTML <meta> descriptions.
Posts: 32509
could you explain the foloowing function please?
GalleryUrlGenerator->parseCurrentUrl();
it's used to get the redirectUrl. But $redirectUrl exists only in 1 case for ShowItem.inc.
What exactly causes G2 to have a redirectUrl??
What is G2's "compressed URL format"?
I'm asking because i need to know how to rewrite GalleryUrlGenerator.class for xaraya integration.
Posts: 32509
note:
if the GalleryUrlGenerator->_baseFile is not a file but a file++ containing a question mark, GalleryUrlGenerator->getCurrentUrlDir() won't work, as it uses regular expressions to get rid of everything but the directory url.
example:
in main.php
$urlGenerator = new GalleryUrlGenerator('index.php?module=gallery2');
won't work.
dirty fix in getCurrentUrlDir():
// $url = preg_replace('|' . $this->_baseFile . '.*|', '', $url);
$url = preg_replace('|index.php\?module=gallery2.*|', '', $url);
Posts: 32509
problem with xaraya:
xaraya itself is quite slow. When integrating G2 as a module of xaraya, it does all the xaraya stuff for each G2 module image request!
So loading of the HTML takes damn long because of slow xaraya + slow G2 (which will improve).
And load time of all images can't be improved because of xaraya
I'm not sure if i will stop here integrating G2 as a xaraya module and work towards a loosely coupled integration where G2 behaves as it was in standalone but internally, it uses xaraya tables where needed.
On the other hand my p3 600MHz without php accelerator isn't the best setup.
I've got the xaraya module working. G2 displays within xaraya and URLs are all ok.
Next step: make G2 use xarayas role table.
xaraya has an elaborated menu API. i don't know how yet, but a perfect integration would remove all menu options from G2 and add them to the xaraya menu, we'll see.
Posts: 8601
Is there some way to make core:DownloadItem requests go directly to G2 instead of going through xaraya?
Posts: 32509
i was thinking of that too. and it should work. but there are issues.
all HTML requests should have a xaraya URL, all (binary) item requests could have a G2 url.
i.e.
HTML request:
domain.com/index.php?module=g2&g2_view=core:ShowItem&g2_itemId=8
and the image request should look like this:
domain.com/modules/gallery2/main.php?g2_view=core:DownloadItem&g2_itemId=10&g2_serialNumber=2
- So the GalleryUrlGenerator baseFile for item requests is different.
- If G2 is integrated as a true module, G2 won't have to authenticate the user as xaraya has already done it. But if we differentiate HTML from item requests, we'll have to authenticate when an item is requested and not, the request was a HTML page.
- etc.
Posts: 181
I had thought that if I move my gallery directories within the gallery module I'm using in MK Portal that could fix my link issue. It could work but I'm still having the same issue where when you click on an image it adds on the url information to the mk portal pulling an error. If I try to modify the URL so it would be a correct link then it breaks out of the module system.
Posts: 7994
Oops, it should be:
You should keep the blocks that look like this:
(that particular block goes into the <body> element and contains pretty much all the G2 output). If you get the latest code, I've put more comments into global.tpl to explain what's going on a little better.
I advise that you make small incremental changes to the global template and experiment with removing things slowly so that you understand what each piece does.
That's right. Now it should show up in the themes list when you edit an album, and in the "General Settings" site admin page.
Ah, ok so my suggested fix above should take care of part of this. You also need to disable short urls so that it's not trying to do any fancy url rewriting. When it's correct, the url should look like this:
Or something similar to that. If your module is set up correctly to include main.php, then G2 should be able to take care of it from there.
Posts: 7994
In global.tpl, everything that the view wants to put into the <head> element is going to be rendered by this tag:
It'll probably contain a <title> element as well as maybe some JavaScript or other stuff. It's not broken out in any way -- it'll all be one block. If you want to see how it's generated, look for any xxxHead.tpl file like modules/core/templates/ShowItemHead.tpl
I agree, but I'm deferring worrying about that for now. Once we've got it working we can work on fine tuning it.
Posts: 7994
G2 allows you to use a "short url" format, so instead of a url like this:
You can have:
The parseCurrentUrl function translates the second format into the first format so that the rest of the code can key off of the "view" and "itemId" values.
For integrations, let's not use the short url format for now. Just leave that function alone.
Posts: 7994
We're making the G2 stuff much faster, as you mentioned. I wouldn't worry about Xaraya speed for now -- they're probably going the same route as G2 is and optimizing at the last minute. It'll get faster (I have faith -- those guys are smart).
Sweet! Got a demo url for us?
I have a tentative plan for how to do that. For now, we should just duplicate the G2 functionality into Xaray menus (and do all the heavy lifting in the Xaray module). Later on we can implement a way to disable that functionality in G2 so that there isn't a weird overlap.
Great work, valiant!
Posts: 181
Where do I disable short urls? There isn't a selection in the config like there was with G1.
Ok let me take a look at my module to make sure its setup correctly that will work with MK Portal and G2. Its basically setup so that the output of the module, since they can't use include with this version they have implode. So I used implode with the index.php and I even tried main.php but you said I have to include in the body:
{include file="gallery:`$main.viewBodyFile`" l10Domain=$main.viewL10Domain}
Here is what I have for the code for my module. I use the output so that it places it within its own block inside MK Portal, implode includes the page (tried both main.php and index.php). The printpage 1 1 tells it to have the left and right column. Where would I put the above code then?
Posts: 32509
gallery2/main.php?g2_view=core:SiteAdmin
scroll down... URL Style... Use short URLs? No
Posts: 7994
I'm confused. Earlier I thought you said that you were calling include() on main.php. But now I see you're using file() on a url. That's not going to work because you're making a second request back into your webserver to get the data, so no information sent to the outer request is going to get propagated. Instead, you should do this:
Then edit main.php and at the bottom change:
to:
You may need to tinker with it a little bit, but that should get you moving in the right direction.
Posts: 32509
Actually I don't want to spend 1 hour to understand how smarty and your template system works . Just tell me if it's difficult to get following components stored in different variables, prefereably in main.php:
- HTML page title
- stylesheet import links
- javascript that must reside in the <head> section
- HTML redirects
- other stuff that G2 needs to be in the <head> section
thank you
@post above:
I'm doing exactly as you describe it. I guess I'll change it to output buffering. I start ouput buffering before G2 main.php is called and get the output contents after G2 has finished the job.
@$showGlobal:
question: in main.php there's a variable "$showGlobal" only set to false, if the view is immediate (binary data request).
is it really meant to indicate binary data requests or does it mean something different and i shouldn't use it as a flag for "this request was a download binary data request" flag?
@menu:
the G2 menu options are context / view sensitive. different users have different menu links in different views of G2.
There is no API in G2 to get all menu links for a view, is there?
@user / entities:
a GalleryUser is a GalleryEntity and as such it has an entry in the GalleryEntity db table.
If I create a XarayaUser, i'll have to create role in xaraya, and create a GalleryEntity with the user_id of that role, right?
If a xaraya role is deleted, I'll have to delete the corresponding entity in G2, right? I guess xaraya's event system should help doing this.
Posts: 32509
PS: Any idea why G2 in xaraya should behave differentely in opera than in firefox??
When browsing my integration with firefox 0.9.2 the slideshow is the only thing that produces wrong URLs ( "Pause", "Back One Image", "Show More Info" all point to "index.php" instead of "index.php?loooong_parameters".
When browsing with opera, these links are ok.
Browsing with firefox in G2 standalone shows correct slideshow links.
Strange...
Does slideshow module make use of some rare GalleryUrlGenerator methods or the like?
Posts: 7994
What're ya saying? G2 is complicated? :D
The short answer is that you can't get that stuff separately right now. We return it in one undifferentiated block. If it's really important for you to be able to get this information separately I think I can rework the template layer to get it broken out. It will require some trickery to do it in a way that gives our template designers flexibility, but we can work it out.
That's a good idea for the time being. We don't want to use output buffering in the long term if we can avoid it because it leads to too many copies of the data. I'll rework GalleryMain() to return the $html instead of printing it and when I do that you'll be able to stop using output buffering.
Originally that variable meant "do we use the global template or not?". But to keep the global template simple, I split it out into several different ones (redirect, error, standalone, global) all of which can be themed by editing the templates. If showGlobal is off it means that the view expects to send back the complete reply itself and it doesn't want any templates to be rendered on its behalf. I think you can safely use it as a "this request was a chunk of data that I can't interpret" flag.
It's not in the GalleryCoreAPI yet, but there is a way. You can use the following methods that are currently in GalleryLayout:
System links are ones that apply to all items (like showing the "Site Admin" link to admins).
That will get you a data set broken down by module of links. The links themselves are in a format that you can feed into GalleryUrlGenerator so you shouldn't have to munge them at all. I'm not quite sure what Xaraya needs for this, so let me know if you want me to explain in more detail. If you want to see what the results of these calls look like, you edit layouts/matrix/layout.inc and look for where it calls _getModuleItemLinks() and right after that do a "print_r($tmp)" and then look in the HTML source of the resulting page to see what a typical breakdown looks like.
I was thinking that you could simply avoid creating anything in the GalleryEntity table. XarayaUser extends GalleryUser and overrides the load/save methods to draw from the xaraya tables, then we change the DatabaseStorage to remap [GalleryUser::id] to xaraya_user_table.role_id (for example). That way we could avoid having to do any synchronization at all. Did I misunderstand your question.[/]
Posts: 7994
I don't see anything obvious in the slideshow module that would generate bad urls. Once you get most things working, we can take a more in-depth look at that (investigating the HTML generated by the slide show should be indicative).
Posts: 8601
All those links use javascript in onclick.. the content of the href shouldn't matter.
Posts: 32509
If I get the head part as one big block,i'll have to parse it for the title and the other elements. If you prefer that, ok.
But there is not only 1 "print" in main.php, above the definition of function GalleryMain() there are other print calls.
And what happens if another G2 module derives GalleryUser for it's own purpose? This class would have GalleryUser as parent and GalleryEntity as grandparent. It wouldn't use XarayaUser, it would call the methods of GalleryUser and GalleryEntity, right?
Posts: 32509
Silly me, it was only rendered differently, actually both have the same url, sorry. I was confused by another behaviour, couldn't log in with firefox but with opera, but that was a caching problem with firefox. then i observed this "discrepancy" and thought there's something strange going on
Posts: 32509
problemo:
Both, G2 and xaraya, use adodb. And adodb uses some PHP wide constants. G2 is initialized second and thus uses some constants that it would have set on another value!
examples:
'ADODB_DIR', 'ADODB_ERROR_HANDLER', 'ADODB_PHPVER'.
While most queries are not negatively affected by these constants, i can't use the G2 trace mode 'sql' as it uses $db->LogSQL which is part of adodb and depends on ADODB_DIR, so it uses the LogSQL() method from xar-adodb and it doesn't work.
DB Errors are handled by xaraya but that's ok i guess.
Everything worked fine, G2 works in xaraya, but I can't use the G2's SQL tracer anymore.
Posts: 7994
That's not preferable, but it'll have to do for now.
None of those print calls will be used, unless there's an error of some kind. And those prints are outside of GalleryMain() and if there is an error, they would happen after GalleryMain() is called so we should be ok returning html from GalleryMain.
I wrapped all of this in GalleryMain so that we could have a way to abort in case of errors. You can only do that if you're in a function (unless you want to use goto statements of some kind). I think that conceivably we should wrap all of the main.php in another function that simply returns HTML (maybe we should do this in index.php) to give you a single entry point that you can call.
The short answer is that those modules wouldn't work in G2 when G2 is embedded in Xaraya. If we can figure out a way to make them work, that'd be great, but my guess is that there won't be so many of those types of modules to begin with and it's ok by me if not all functionality works in all places.
Posts: 7994
Ugh. I was afraid of this. I think I will probably have to start patching ADOdb to have a separate version specifically for G2 (I believe this is what PostNuke does also) to avoid conflicts.
Posts: 32509
@adodb: it's not a top priority, but it could become a problem if xaraya or G2 change the behaviour of their adodb layer.
Posts: 32509
Does anyone know of something like a "database link" in postgresql?
In oracle you can query tables from different databases in a single statement using a "database link".
In mysql you can do the same by putting the "dbName."before the tableName for tables of other databases.
I'm asking because I don't know if I should make it a requirement that G2 and xaraya are in the same database. Both have their table prefix, that's not the problem, but why not be flexible?
It seems as if postgresql can't do this, so I'll make it a requirement to have both apps in the same db.
source: postgresql 7.4 manual, and google doesn't list "database link" results for postgresql
Posts: 181
I'm going to start over from scratch. It seemed with every change it just went from bad to worse and its not working properly at all. I'll print everything out so I can try to keep the changes out in order, as well as a better change log to hopefully better troubleshoot what isn't working.
Posts: 32509
I'm slowing down, don't know exactly how to code in G2, change/derive the classes etc. Actually I know the technical stuff, but all the consequences of deriving / changing a core class like User are a little bit overwhelming.
However, I changed 3 methods in DatabaseStorage.class
- function _translateTableName($tableName): new: returns ($table,$alias,$whereCondition)
- function _translateColumnName($columnName, $class = null): new: optional $class parameter
- function _translateQuery($query): new: translates G2->xaraya too
Now they translate all G2 SELECT statements, replacing User/Group/UserGroupMap tables/columns to xaraya xar_roles/xar_rolemembers tables.
Now I need to add g_grouptype and g_language to the xaraya roles table and it should work.
Posts: 7994
valiant, I completely understand how you feel. For now I would try not to worry too much about the consequences. All decisions made now are reversible so you should continue to experiment until we understand all the various issues that are involved with integrating these two apps together.
At some point we'll want to take your accumulated knowledge and start over again to make a cleaner integration, then start refactoring your changes out into a module. At that point, it might make sense for me to take your changes and make a pass over it myself so that I can offer up my perspective.
Everything you've done up to now sounds great -- keep it up! Let me know when you think you're at a point where most of the app is functional and we can review.
Posts: 32509
bharat,
You said, XarayaUser should extend from GalleryUser. You said also, XarayaUser should not have en entry in the entities db table / shouldn't be a GalleryEntity even it's derived from GalleryUser which is a GalleryEntity.
But all insert/update/deletes are handled using Entity::Id.
i.e. in init.php you get the user data by GalleryEntitity::id.
list ($ret, $activeUser) = GalleryCoreApi::loadEntitiesById($activeUserId);
So, should I replace these code snippets?
Or we decide that a XarayaUser is a GalleryEntity. xaraya knows events and everytime a XarayUser was modified in xaraya, we could update the GalleryEntity.
And most of the work is done in DatabaseStorage.class.
I'd prefer anyway, if ALL queries (select/update/insert/delete) went through the same translation function. Or perhaps a translation function per query type. There exists a translation function for select statements and we could do the same for the other three query types update/insert/delete. DatabaseStorage->loadEntities($id); would first create the query using the [Class::member] notation, pass it through the translate function and execute it.
At least the whole GalleryCoreApi must work out of the box as other modules rely on it, right? Other modules may still use GalleryCoreApi::loadEntitiesById($someuserids); etc.
Generally, I'm trying to allow all possible queries. What if future G2 modules query the user language or update userproperties, etc.
This implies to above, translate each query in the DatabaseStorage class.
Do you think that makes sense or should I change all queries manually??
Posts: 7994
Sorry to take so long to reply. I'm hip deep in a pretty major optimization refactor that's taking up all of my evening time.
So .. argh. I forgot about the fact that we're loading all entities generically. I think that you're right that we should not break GalleryCoreApi::loadEntitiesById() because that will certainly lead to failure for other modules.
I'd rather not depend on Xaraya events to keep our entity table up to date because if we miss an event, we can wind up in a broken and corrupted state. It may be impossible to avoid that, though. The way that it works now is that given an id, we look in the entity table to figure out what kind of class it is, then ask the class what members it expects, then look up that information in the database. So we could theoretically modify DatabaseStorage::_identifyEntities so that if it checks our local entities table and there's no entity for the id specified, we check the Xaraya user (or group) table to see if the id is a Xaraya user or group id. The problem with that is that I'm pretty sure we'll wind up with duplicate ids -- ie, Xaraya user ids will wind up having the same value as one of our random entities (like a photo item) and then we'll do the wrong lookup.
I'm not exactly sure what to tell you at this point. We could maybe try to get fancy and differentiate Xaraya ids from G2 ids in the database so that we don't have conflicts. Or we could fall back on doing synchronization using Xaraya events to keep our tables in sync.
For now, I suggest that you modify the line that loads the active user in main.php just so that you can keep going working on it and see what other problems are there. Sometime soon (maybe this weekend?) I'd like to sync up with you and look at the code changes you've made and try working on it a little bit also on my end to see if we can come up with some abstractions to make this easier.
By the way, with any luck I'll be committing a big refactor tonight that will change around a lot of the initialization code. Be sure to make a backup of your changes before you do any cvs ops just in case.
Posts: 32509
grmpf, phpbb invalid session. type again please...
Personally I'd prefer it, if xaraya role_ids = G2 user_ids. I guess it would need much more changes, if a xaraya user was not an entity.
another adodb issue:
problem: get newEntity() id fails, guess adodb is using config from xaraya and db from g2 resulting in a default value '0'
in DatabaseStorage.class->newEntity():
$id = $this->_db->GenId($this->_tablePrefix . DATABASE_SEQUENCE_ID); returns '0'
Most of what I've done 'till now is:
- create a gallery2 module in xaraya: wrapper for main.php, some other xaraya stuff, working on hooks (events) to insert/update G2 entity whenever a xaraya role is created/deleted/...
- modified functions: translateQuery, translateColumn, translateTableName, loadEntities
- thinking of solutions for the Galleryuser member "language"
- added a function to add slashes to the UrlGenerator baseFile for regular expressions
- beginning to use xaraya hooks (event system) to sync the G2 user/group Entities as part of the gallery2 module in xaraya
What I'll do tomorrow:
- try to solve the db->GetId() problem because it's a blocker
- Work on methods of DatabaseStorage.class. Target all methods should work in a integrated G2.
- see what i have to change to create a user in init.php
Posts: 32509
@adodb GenId problem:
G2 uses the adodb class definitions from xaraya and xaraya has hasGenId set to false.
As a temporary fix I set hasGenId = true in the xaradodb/drivers/adodb-mysql.inc.php in xaraya.
Posts: 32509
Actually I want a solution that is applicable to most CMS/external user/group management and relying on the CMS to create G2 Entities for Users/Groups is not the easiest thing. You'd have to change the code of some core files of the CMS in most cases and that's not an easy integration.
2 options:
1. GalleryCoreApi::loadEntitiesById() is used about 35 times to get a user/group instance by id. Perhaps half of that is in modules/core.
I'd say, if we call GalleryCoreApi::loadEntitiesById() to get a user/group, we know what the returned instance will be in advance. Sometimes we may not know if it is a user or a group in advance, but we know that it must be a either a user or a group.
What I'm proposing:
change the function GalleryCoreApi::loadEntitiesById($ids) to
GalleryCoreApi::loadEntitiesById($ids, $hints = null).
In all cases where we call GalleryCoreApi::loadEntitiesById($ids) to get a user/group, we will set $hints accordingly, i.e. $hint = array('GalleryEntity' => false) for each id that is either a user or a group.
That would require to change GalleryEntityHelper_*.php accordingly and DatabaseStorage.class::loadEntities($ids) too.
We'd have to do the same for: GalleryCoreAPI::deleteEntityById(). Or would you prefer using new/different functions everywhere we load/delete a user/group?
I count 25 files to where load/deleteEntityById is called or handled. That makes about 40 changes (add 'NoEntity' as a hint or process the hint) in total.
Consequence: We'd have two sets ids but they are not interfering.
What you think?
2. User/Group don't extend from GalleryEntity
It's a possibility, but you'd have to change a lot and it's not a good solution. Please don't do it.
PS: Please announce your new "performance" build when it's available via cvs
Posts: 8601
Looks like this change has been committed, about 8 hours ago:
Posts: 974
I'm confused - what's to stop us from extending the gallery user to have a xaraya user id in addition to the element id? The Xaraya module could clean up the G2 users based on the Xaraya table each time it is loaded - create any new ones and delete any missing ones...
Posts: 32509
What you propose is an asynchronous method, violating data integrity. I don't like syncing. What if someone uses GalleryRemote in between etc.
And sync G2/xaraya for every request isn't very effective.
Goal: Users / Groups are managed by the CMS (xaraya). You don't create/update/delete users in G2 which is embedded in the CMS.
And the CMS doesn't create a GalleryEntity when creating a user/group.
So there is no entry in the GalleryEntity table for a CMS user and GalleryCoreAPI::loadEntitiesById($ids) won't work.
But if you ultimately don't want to change GalleryCoreAPI::loadEntitiesById($ids), we could add another column to the GalleryEntity table called 'external_id'. Those CMS that have events would create a G2 Entity with 'external_id' = CMS user_id whenever a user has been created. Those CMS that don't have events, would depend on G2 to sync on each request and create entries in GalleryEntity for all missing users. But as I said, I don't like this hack.