The ratings in the nodeapi example module don't keep up with the revisioning system. Meaning: The rating stays the same regardless of new ratings for new node revisions. This might also be the case for the 7.x branch, but I have no way to test it at the moment.

A code-filled half-hour after discovering this, I have it fixed and would offer a patch, but I'm not comfortable enough with those tools to do it. Any link to a helpful cheat sheet would be appreciated.

As a side note, this patch might be a good example of how to do a schema update, as well. :-)

Comments

rfay’s picture

Hi @Mile23! Fantastic. Your contribution is much appreciated.

http://drupal.org/patch is the place to start with patches.

Since you're the contributing sort, it's worth your time to learn how to do it.

However, if you just can't, post an archive of some type and I'll extract the patch from it. Again, though, learning this process makes you so much more powerful as a contributor.

Thanks!
-Randy

mile23’s picture

StatusFileSize
new2.15 KB
new2.87 KB

Thanks much, Randy. I just learned how to get all diff'd -up.

Now we try this and see...

rfay’s picture

Status: Active » Needs review

To get your patch tested, then you put the status as "needs review"

Note that the whole thing goes into one patch (both changes). This may not pass the tests because it's going to test each one separately.

Congrats on getting patching going!

mile23’s picture

Thanks again, Randy. Seems I passed. woot. :-)

rfay’s picture

Thanks for the good work. This looks OK to me.

However, we *really* need tests for this module. It's one of the few without tests. You code like you know how to do tests.... Any interest?

rfay’s picture

Status: Needs review » Needs work

OK, I finally took the time to look at this carefully.

The real issue this patch is trying to address is that the rating is not kept with the revision, which, it's true, is correct. The purpose of this example is to demonstrate how to use the node APIs, and where the rating is stored is not all that relevant to it, but I agree that the fix you propose is much better.

However, new revisions are not "lost" - the most recent revision set on a node is the one that's kept.

Problems running the update hook - probably due to adding new column (with an index) while the old one is still there.

The following queries were executed
nodeapi_example module
Update #6002

    * Failed: ALTER TABLE {nodeapi_example} ADD `id` INT auto_increment DEFAULT NULL, ADD PRIMARY KEY (id)
    * Failed: ALTER TABLE {nodeapi_example} CHANGE `id` `id` INT NOT NULL auto_increment
    * ALTER TABLE {nodeapi_example} ADD `vid` INT unsigned NOT NULL DEFAULT 0
    * UPDATE {nodeapi_example} SET vid = %d (0)

or as drush shows it:

Executing nodeapi_example_update_6002                                [success]
WD php: User warning: Multiple primary key defined                   [error]
query: ALTER TABLE nodeapi_example ADD `id` INT auto_increment
DEFAULT NULL, ADD PRIMARY KEY (id) in _db_query() (line 128 of
/home/rfay/workspace/d6git/includes/database.mysqli.inc).
WD php: User warning: Unknown column 'id' in 'nodeapi_example'       [error]
query: ALTER TABLE nodeapi_example CHANGE `id` `id` INT NOT NULL
auto_increment in _db_query() (line 128 of
/home/rfay/workspace/d6git/includes/database.mysqli.inc).
ALTER TABLE {nodeapi_example} ADD `id` INT auto_increment DEFAULT    [error]
NULL, ADD PRIMARY KEY (id)
ALTER TABLE {nodeapi_example} CHANGE `id` `id` INT NOT NULL          [error]
auto_increment
ALTER TABLE {nodeapi_example} ADD `vid` INT unsigned NOT NULL DEFAULT[success]
0
UPDATE {nodeapi_example} SET vid = %d (0)                            [success]
Multiple primary key defined                                         [error]
query: ALTER TABLE nodeapi_example ADD `id` INT auto_increment
DEFAULT NULL, ADD PRIMARY KEY (id) in _db_query() (line 128 of
/home/rfay/workspace/d6git/includes/database.mysqli.inc).
Unknown column 'id' in                             [error]
'nodeapi_example'

ilo’s picture

Assigned: Unassigned » ilo

let me check..

ilo’s picture

Version: 6.x-1.x-dev »
Status: Needs work » Needs review
StatusFileSize
new9.77 KB

I'm not happy including an update function in the example module as it may lead to confusion unless the purpose of the module is to perform an update operation, so I'll forget that part and focus on the revision system only. I've included a testcase for the revision stuff, now rating is saved between revisions as expected.

Lets review this and I'll backport the changes to d6.

ilo’s picture

Title: 6.x nodeapi example - no room for revisions » nodeapi example to support revisions
Category: bug » task

Changed to a better description of the issue.

ilo’s picture

After an irc convo with chx and rfay, probably this module needs to be refactored at all to support fields, instead of using its own database tables.. so, rfay, you choose: mark as rtbc and commit, and then we work on a rewrite, or mark as needs work and we begin the field implementation.. :)

rfay’s picture

rfay’s picture

Status: Needs review » Reviewed & tested by the community

Took a look at this on the plane today, and I think we should go with it. I'm wide open to new examples that demonstrate fields, but this one has a lot of work done on it and we should get it in.

rfay’s picture

Status: Reviewed & tested by the community » Fixed
rfay’s picture

Version: » 6.x-1.x-dev
Status: Fixed » Patch (to be ported)

And should this be backported to D6?

mile23’s picture

Wow, I hadn't looked at this in far too long. Yay committed for D7. :-)

I'll revisit my patch so that it changes the schema without creating an update, even though of course that's not good behavior for any other module.

mile23’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new4.32 KB

OK, basically the same patch, without an update function, for D6.

Status: Needs review » Needs work

The last submitted patch, d6nodeapi_829536.patch, failed testing.

rfay’s picture

Status: Needs work » Needs review
StatusFileSize
new4.3 KB

@Mile23, you forgot the --no-prefix in your git diff

git diff --no-prefix DRUPAL-6--1 (or whatever)

That said, I have had a LOT of trouble getting the testbot successful in the last couple of days. However, your patch is in fact faulty. So maybe it will get through when rerolled.

Attached is a straight reroll.

Status: Needs review » Needs work

The last submitted patch, examples.d6nodeapi_829536_18.patch, failed testing.

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new4.3 KB

Heh. You give me too much credit to say I *forgot* the --no-prefix. :-)

However... Let's see how this works.

rfay’s picture

I don't actually understand what's going on with this "Drupal installation failed" thing.

mile23’s picture

It installs just fine for me on drupal 6.19.

Status: Needs review » Needs work

The last submitted patch, d6_nodapi_noprefix-829536.patch, failed testing.

mile23’s picture

I wonder if it's perhaps trying to install the module 'examples.'

rfay’s picture

I'll track it down. It may be that all D6 contrib testing is failing.

rfay’s picture

Assigned: ilo » Unassigned

@Mile23, I just noticed that the tests from D7 didn't make it into your patch. Could you fix up the tests and include them?

(Don't worry about the testbot failures. Until we get that working again we'll have to go by manual testing.)

mile23’s picture

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new11.49 KB

Voila.

rfay’s picture

Status: Needs review » Fixed

Committed:
http://drupal.org/cvs?commit=467394
and http://drupal.org/cvs?commit=467396

Thanks so much, @Mile23. You really hung with this one! You're welcome anywhere here in the Examples project and your contribution is very much appreciated.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.