This is a very simple module that allows you to track page views on your site without having to enable the core statistics module.

This is usefull if you have a big site with many content types but only need the statistics for some of them, so you don't need to create write queries to the database unnecessarily on the whole web.

Note that this module is much simpler than the core statistics module and only records the page total counts and the last visited date.

Usage:

1) Install as usual.
2) Go to admin/config/mvct and select the content types you want to enable the statistics for.
3) Use the statistics generated in any view, either as a field, filter or as a sort criterion.

Project page:

https://drupal.org/sandbox/marcoscano/2132379

Git:

git clone http://git.drupal.org/sandbox/marcoscano/2132379.git mvct

CommentFileSizeAuthor
#34 db.patch928 bytesbasvanderheijden

Comments

PA robot’s picture

Status: Needs review » Needs work

There are some errors reported by automated review tools, did you already check them? See http://pareview.sh/pareview/httpgitdrupalorgsandboxmarcoscano2132379git

We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)

Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).

I'm a robot and this is an automated message from Project Applications Scraper.

marcoscano’s picture

Status: Needs work » Needs review

The only errors reported are supposedly missing doc blocks that are present, I guess it's a false positive of the script, or I don't quite understand what the errors mean

PA robot’s picture

Multiple Applications
It appears that there have been multiple project applications opened under your username:

Project 1: https://drupal.org/node/2132599

Project 2: https://drupal.org/node/2020647

As successful completion of the project application process results in the applicant being granted the 'Create Full Projects' permission, there is no need to take multiple applications through the process. Once the first application has been successfully approved, then the applicant can promote other projects without review. Because of this, posting multiple applications is not necessary, and results in additional workload for reviewers ... which in turn results in longer wait times for everyone in the queue. With this in mind, your secondary applications have been marked as 'closed(duplicate)', with only one application left open (chosen at random).

If you prefer that we proceed through this review process with a different application than the one which was left open, then feel free to close the 'open' application as a duplicate, and re-open one of the project applications which had been closed.

I'm a robot and this is an automated message from Project Applications Scraper.

klausi’s picture

Sorry for the noise, the robot stumbled a bit on broken issue queue search links. Your other application is closed already, so everything fine here.

perignon’s picture

Couple things.
Your git repo link should be:
git clone http://git.drupal.org/sandbox/marcoscano/2132379.git mvct

The link you have has your username in it which will fail for anyone trying to review the project.

The review bot is very picky and it's looking for doxygen style comments. What it's seeing is this. This is your function doc block

/*
 * Helper function to get the existent content types from the database.
 *   returns an array in the form ("content type machine name" => "human name").
 *
 * @return Array
 *   Returns an array containing all active content types from the database.
 */

That should be

/**
 * Helper function to get the existent content types from the database.
 *   returns an array in the form ("content type machine name" => "human name").
 *
 * @return Array
 *   Returns an array containing all active content types from the database.
 */

Notice the single extra "*" at the first line of the comment blog. Some of your doc blocks are right some aren't. That should clear up the auto review issues found.

perignon’s picture

Status: Needs review » Needs work

Forgot to change the tagging...

marcoscano’s picture

Issue summary: View changes
marcoscano’s picture

Status: Needs work » Needs review

Many thanks @Perignon for the corrections!

No more styling errors in the script, yay!

perignon’s picture

Woohoo... All clean! I'll test the module out tomorrow if no one else does before me.

joshi.rohit100’s picture

Status: Needs review » Needs work

Hi,

1. In your mvct_settings form, you have called your custom function for content types. Instead of this you can use node_type_get_names() directly in #options.
2. You should add your mvct.admin.inc and mvct.views.inc files in info file.
3. You have defined your helper functions in module file. Instead of this, define them in your mvct.admin.inc file as module file parses on every page request and will make it heavy.

Thanks

marcoscano’s picture

Status: Needs work » Needs review

Thanks @joshi.rohit100 for your review.
The modifications indicated were implemented, except for #1, because according to the _node_types_build() documentation the returned result may include non-active content types, which we don't want in our case

perignon’s picture

Status: Needs review » Reviewed & tested by the community

My second review of this module. Module works as described and provides statistics on contents types viewed.

Developer is correct in his statement. His function only returns active content types. The core function returns all content types despite their condition.

Other changes were made according to feedback.

joshi.rohit100’s picture

If you want only active content types, then try this https://api.drupal.org/api/drupal/modules!node!node.module/function/node_type_get_types/7

Stil if you want to access data directly from the db, then use caching so that once get the data, it available in the cache and no need to access data on every page request.

thanks

joshi.rohit100’s picture

Status: Reviewed & tested by the community » Needs work
marcoscano’s picture

Status: Needs work » Reviewed & tested by the community

The function indicated in #13 is the one that may return non active content types.
I don't see the need of caching for this function (mvct_get_content_types()), once it's not called on every page request, only on the configuration page, to create the config form.

Returning to RTBC as per #12 review

Many thanks @Perignon and @joshi.rohit100 for your time and reviews

perignon’s picture

No problem! Glad to help.

Marcoscano is correct. The function in #13 is calling this function: https://api.drupal.org/api/drupal/modules%21node%21node.module/function/...

That will return all node types available in the database no matter what their status is. For the purpose of showing stats to your user, you don't want to show them stats on a node type that you may have disabled for some reason.

marcoscano’s picture

Priority: Normal » Major

switching to major after 2 weeks

marcoscano’s picture

Priority: Major » Critical
ram4nd’s picture

Priority: Critical » Normal
  • Do reviews on other projects to get: PAReview: review bonus.
  • Don't change the status to mayor or critical. There is a lot of us and few of them.
  • You should make necessary indexes for the db schema.
ram4nd’s picture

Status: Reviewed & tested by the community » Needs work
marcoscano’s picture

Priority: Normal » Critical
Status: Needs work » Needs review

@ram4nd:
- Priority elevation guidelines are defined here: https://drupal.org/node/539608
- Can you please justify the need of the indexes, once the primary key is defined? (https://drupal.org/comment/956205#comment-956205)

ram4nd’s picture

Ok, thanks didn't know that.
You need indexes if you do queries where you have conditions other than the primary key.

devd’s picture

Hi marcoscano,

You should use drupal inbuild function node_type_get_types() to fetch all active content types from the database in place of mvct_get_content_types().

marcoscano’s picture

@devendra-yadav,

This point was discussed earlier in this issue, please see comments #10, #11, #12, #13, #15 and #16

In any case, this function is called only when the administrative UI form is built, which is going to happen probably only once or twice, during the site build phase.

devd’s picture

Status: Needs review » Needs work

Hi marcoscano,

I am agree with you but i review your query. you are using only two fields(type and name) but you are fetching all fields from node_type table. So it is needed optimization in query.

Second thing: Suppose no content type is active in that case your form will display the
Title: Select the content types that will be monitored and
Button : Save Configuration.
Actually there is noting to save and when i click on the button it will dispaly a message "The configuration options have been saved." Actually there is noting to be saved.

marcoscano’s picture

Priority: Critical » Normal
Status: Needs work » Needs review

Wooow... You are saying that there might be a hypothetical user who wants to store statistics for his site where there is no active content types! That's what I call an edge case...

Anyway, modifications applied, code updated.

Counters running from zero again...

dan.ashdown’s picture

Status: Needs review » Needs work

Hi marcoscano,

Pareview automated testing found a number of issues:

Coder Sniffer has found some issues with your code (please check the Drupal coding standards).
FILE: /var/www/drupal-7-pareview/pareview_temp/mvct.admin.inc
--------------------------------------------------------------------------------
FOUND 2 ERROR(S) AFFECTING 2 LINE(S)
--------------------------------------------------------------------------------
28 | ERROR | else must start on a new line
70 | ERROR | Files must end in a single new line character
--------------------------------------------------------------------------------

FILE: /var/www/drupal-7-pareview/pareview_temp/mvct.info
--------------------------------------------------------------------------------
FOUND 3 ERROR(S) AFFECTING 2 LINE(S)
--------------------------------------------------------------------------------
5 | ERROR | It's only necessary to declare files[] if they declare a class or
| | interface.
6 | ERROR | Files must end in a single new line character
6 | ERROR | It's only necessary to declare files[] if they declare a class or
| | interface.
--------------------------------------------------------------------------------

Codespell has found some spelling errors in your code.

./README.txt:6: usefull ==> useful

I found some issues when conducting a manual review:

  1. Double space in @file comment in mvct.views.inc (sorry!)
  2. Double space in @file comment in mvct.install (sorry again!)
  3. In mvct.info you're including mvct.admin.inc, you don't need / shouldn't do this here. You're also including it in your menu hook which is correct. By including it in the info file you're including it on every page of your site.
  4. Double space in @file comment in mvct.admin.inc (sorry again! copy paste error? :) )
  5. In mvct.admin.inc in mvct_get_content_types(), you should use db_query() instead of db_select() for simple queries where you're not conditionally adding conditions etc. See: https://drupal.org/node/310075
  6. mvct_get_record() query as above.

Once the above minor issues are sorted think you're good to go.

marcoscano’s picture

Status: Needs work » Needs review

@Dan.Ashdown,
Thanks for you review!

Implemented the modifications suggested.
I hope everything is fine now

priyankapareya’s picture

Hi,

The menu item 'admin/config/mvct' in file mvct.module line 14, is not reflected under any section in the configurations page.
It would be much better if users can see the link to your module settings page.
You can probably make two menu items so that it appears in the configuration page or can be included inside any other menu item already present in the configurations page.

marcoscano’s picture

Priority: Normal » Major

Elevating priority

Although I don't thing it's really necessary (once it's well documented and available in the modules list page), I have changed the configuration url in order for it to appear also in the admin/config general page.

marcoscano’s picture

Priority: Major » Critical
BigEd’s picture

Status: Needs review » Needs work

Hi marcoscano,

Pareview automated testing found a number of issues:

FILE: /var/www/drupal-7-pareview/pareview_temp/README.txt
--------------------------------------------------------------------------------
FOUND 0 ERROR(S) AND 1 WARNING(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
20 | WARNING | Line exceeds 80 characters; contains 81 characters
--------------------------------------------------------------------------------

FILE: /var/www/drupal-7-pareview/pareview_temp/mvct.info
--------------------------------------------------------------------------------
FOUND 1 ERROR(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
5 | ERROR | It's only necessary to declare files[] if they declare a class or
| | interface.
--------------------------------------------------------------------------------

FILE: /var/www/drupal-7-pareview/pareview_temp/mvct.module
--------------------------------------------------------------------------------
FOUND 1 ERROR(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
16 | ERROR | Do not use t() in hook_menu()
--------------------------------------------------------------------------------

I will take a look through the code in some more detail and report back.

Good work

marcoscano’s picture

Priority: Critical » Normal
Status: Needs work » Needs review

fixed

basvanderheijden’s picture

Status: Needs review » Needs work
Issue tags: +code review
StatusFileSize
new928 bytes

Hey Marcoscano,

I've tested your module, and must conclude that it works fine.
However, there is one small change I'd implement in code. If I were you, I'd use the Database Abstraction layer instead of direct calls to db_query().
I've included a patch with the SQL statements rewritten to DBTNG. On the plus side, it saves you one loop as well :-)

marcoscano’s picture

Status: Needs work » Needs review

@basvanderheijden, thanks for your time reviewing the code.

Nevertheless, it would be helpful also to check the other reviews done to the same project, to see the history of the changes made. In this case, you can see that according to the suggestions of #27, all the db_selects were replaced by dy_querys because they are simple queries and don't justify the use of dynamic queries.

Marking it back to needs review.

prabeen.giri’s picture

I have one minor optimization point to make:

On line number 43 and and 48 you have the same assignment statement being used.

$record->last_viewed = REQUEST_TIME;

You can remove the former one.

marcoscano’s picture

Fixed

jjozwiak’s picture

I was going to build a module specifically to track views of my blog content type only and then came across this. I have tested the module and it works as described. I have also reviewed the code and do not see any problems with its implementation.

jjozwiak’s picture

Status: Needs review » Reviewed & tested by the community
kscheirer’s picture

Status: Reviewed & tested by the community » Fixed

Non-blocking issues:

  • You might want to note somewhere that this module only counts the 'full' view mode. With modules like display suite that use all kinds of other view modes, I think the clarity would help.
  • Providing a default view that makes use of your data would be a nice addition

Checked for security, licensing, Drupal API, and individual account issues.

Thanks for your contribution, marcoscano!

I updated your account so you can promote this to a full project and also create new projects as either a sandbox or a "full" project.

Here are some recommended readings to help with excellent maintainership:

You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and stay involved!

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

Thanks to the dedicated reviewer(s) as well.

marcoscano’s picture

@kscheirer
Thanks for your time, all suggestions were implemented. (Improved doc and default view)

Status: Fixed » Closed (fixed)

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