Any time line when this be port to drupal 7?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Liam McDermott’s picture

Title: Any plan to port to Drupal 7 » Drupal 7
Category: feature » task

Plans to port to Drupal 7? Certainly! :)

Unfortunately I cannot provide a timeline unless it's for a paid project. If you need me to cost it out, drop me a line. My rate is currently €50/per hour.

I'm happy to review patches too.

Tebb’s picture

Title: Drupal 7 » Upgrade to Drupal 7

Subscribing.

andypost’s picture

subscribe

samgreco’s picture

Subscribe

Tebb’s picture

Title: Upgrade to Drupal 7 » User Stats: Upgrade to Drupal 7

Changed title to display module name in Dashboard -> Your Posts.

danielm’s picture

Subscribe

SilviaT’s picture

sub

Shadlington’s picture

Subscribing

OFF’s picture

Subscribe

toxiclung’s picture

+1

izus’s picture

Subscribing

culfin’s picture

subscribe

Panic’s picture

Subscribe

sbsimmons86’s picture

subscribe

likewhoa’s picture

Title: User Stats: Upgrade to Drupal 7 » Port user stats to Drupal 7
Issue tags: +d7 ports

Subscribing

gomezsal’s picture

Subscribing

patoshi’s picture

subb

keltic’s picture

subscribe

RikiB’s picture

subscribing :)

arsunyiu’s picture

subscribe

ConradFlashback’s picture

sub++

kreynen’s picture

I did an initial port of this module http://drupal.org/sandbox/kreynen/1222620

patoshi’s picture

Thank you kreyen... tested and getting this error:

Fatal error: Call to undefined function rules_events_global_user_argument() in

patoshi’s picture

public_html/sites/all/modules/user_stats/user_stats.rules.inc on line 74

seems like the fucntion does not exist in rules version 7... how did u get it to work and patch in the first place if the rules didnt even have this function?

patoshi’s picture

Major errors.. when i visit the user page..

screenshot:

http://prntscr.com/2crkr

Warning: Missing argument 3 for db_query_range(), called in /home/x/public_html/sites/all/modules/user_stats/user_stats.module on line 425 and defined in db_query_range() (line 2301 of /home/x/public_html/includes/database/database.inc).
Notice: Undefined variable: count in db_query_range() (line 2306 of /home/x/public_html/includes/database/database.inc).
Warning: Cannot modify header information - headers already sent by (output started at /home/x/public_html/includes/common.inc:2562) in drupal_send_headers() (line 1039 of /home/x/public_html/includes/bootstrap.inc).
PDOException: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound: SELECT uid FROM {users} WHERE uid NOT IN (SELECT uid FROM {user_stats_values} WHERE name = :name) LIMIT 1, 0; Array ( ) in user_stats_cron() (line 425 of /home/x/public_html/sites/all/modules/user_stats/user_stats.module).

luckystrikerin’s picture

subs

kreynen’s picture

@duckx

I'm not using Rules and didn't update those functions. You know how it goes... just scratching my own itch and all. The original user_stats had the rules calls wrapped in module_exists('rules'), so the function is never called if Rules isn't enabled.

if (module_exists('rules')) {
    rules_invoke_event('user_stats_' . $type . '_' . $op, $uid, $value);
  }

That said I went ahead and commented out all the rules calls until someone has time to update those.

patoshi’s picture

what's a solution you might have to just at least show the post count? what would i need to do to at least get it semi working?

kreynen’s picture

@duckx Really? Your support requests make me think twice about sharing code to move D7 ports forward. I never suggested this was finished, but I've already explained how I implemented it...

http://drupal.org/sandbox/kreynen/1222620

Ran it through Coder, fixed a few queries, and implemented it using at the theme layer using these instructions http://www.apaddedcell.com/an-introduction-user-stats-module-drupal.

Works for my needs. I never used this module in D6 so I'm not sure how some of this is supposed to work. I'll apply patches, but I'm not going to respond to support requests or bug reports without a patch.

Have some respect for my time. At a minimum read what I've already written.

The version in my sandbox is going to be used in a production site in a few weeks, but with a very specific configuration. I don't have a need to update user_stats beyond this point. My goal in sharing the update in my sandbox was to save @Liam McDermott or another developer some time.

I've updated the sandbox page to be 100% clear about this.

patoshi’s picture

sorry for the confusion. i was under the impression you had it semi working without the errors. I didnt know all you did was just run it through the coder module and apply some theme fixes. good to know as ill see if i can take a stab at it since your point me in the right direction.

kreynen’s picture

[kreynen bangs head against wall]

Just so someone else reading this thread is clean, we DO have a semi working version! That is what that screenshot is from and what will be used on a site that is launching next week. It does not generate errors when configure they way we have configured it, but it won't be hard to find something that doesn't work.

If you read the commit log you can see the issues we've found and fixed...

http://drupal.org/node/1222620/commits

We HAVE NOT tested everything that was in the D6 version. We're not using Rules at all on this site. @duckx enabled Rules and got an error. We "fixed" that by commenting out the references to Rules. You'll probably get errors with Views and other feature we aren't using too.

Again, this is an initial port... not a finished, stable release. If you are a developer and want to help push the D7 port forward, it will probably be more productive to post patches to http://drupal.org/sandbox/kreynen/1222620 until @Liam McDermott creates a 7.x branch in the official project.

patoshi’s picture

@kreynen are you on advanced forum or just the regular forum?

snupy’s picture

subscribe

inolen’s picture

@kreynen thanks for the initial work!

I went ahead and got the cron function working:

function user_stats_cron() {
  if (variable_get('user_stats_rebuild_stats', TRUE) &&
    (variable_get('user_stats_count_posts', TRUE) ||
    variable_get('user_stats_count_comments', TRUE))) {
	
    $sql  = "SELECT uid FROM {users} WHERE uid NOT IN
      (SELECT uid FROM {user_stats_values} WHERE name = 'post_count')";
    // Update 25 users per cron run.
    $result = db_query_range($sql, 0, variable_get('user_stats_user_per_cron', '25'));
    $users_updated = FALSE;
	foreach ($result as $update_user) {
      user_stats_post_count_update('reset', $update_user->uid);
      $users_updated = TRUE;
    }
    // If all users have been updated we'll avoid running this expensive
    // query again by setting the following flag!
    if (!$users_updated) {
      variable_set('user_stats_rebuild_stats', FALSE);
    }
  }
  // Fire rules day_older event.
  // This may seem grossly inefficient, but testing showed that, even firing
  // the event for ~100 users, takes less than a second to run when there are
  // no rules using this event. With a rule (that adds a role if the user has
  // been a member for over 1,000 days) cron took an extra ~40 seconds to run.
  // Basically, this has no potential to harm a site's performance, unless a
  // rule is configured.
  // Having said this: if there's a better way, please raise a bug report!
  if (module_exists('rules')) {
    $sql  = "SELECT uid FROM {users} u ";
    // ((last cron - created) - (time() - created)) > one day
    $sql .= "WHERE (FLOOR((:request_time-created)/(60*60*24))-FLOOR((:cron_last-created)/(60*60*24)))>0
      AND uid>0";
    $result = db_query($sql, array(':request_time' => REQUEST_TIME, ':cron_last' => variable_get('cron_last', REQUEST_TIME)));
    $reset_user_count = 0;
	foreach ($result as $update_user) {
      rules_invoke_event('user_stats_day_older', $update_user->uid);
    }
  }
  if (variable_get('user_stats_track_ips', TRUE)) {
    // Delete items from the IP log that are past expiry.
    // TODO Please review the conversion of this statement to the D7 database API syntax.
    /* db_query("DELETE FROM {user_stats_ips} WHERE first_seen_timestamp < %d", REQUEST_TIME - variable_get('user_stats_flush_ips_timer', 31536000)) */
    db_delete('user_stats_ips')
  ->condition('first_seen_timestamp', REQUEST_TIME - variable_get('user_stats_flush_ips_timer', 31536000), '<')
  ->execute();
  }
}

also, a fix for counting comments in user_stats_post_count_update @ line ~891:

      if (variable_get('user_stats_count_comments', TRUE)) {
        $sql = "SELECT COUNT(*) FROM {comment} c
          INNER JOIN {node} n ON c.nid = n.nid
          WHERE c.uid = :uid AND c.status = 1 AND n.status = 1";

finally, a fix to user_stats_ip_address_update @ line ~959:

  $query = db_query_range("SELECT ip_address FROM {user_stats_ips} WHERE uid = :uid ORDER BY first_seen_timestamp DESC", 0, 1, array(':uid' => $uid));

Sorry for not making a patch, just in a hurry but wanted to put this out there.

kreynen’s picture

@duckx I am using Advanced Forum.

@inolen Committed.

http://drupalcode.org/sandbox/kreynen/1222620.git/commit/9ba6456

I'd REALLY encourage you to use git when working with a dev branch of a module... or in this case a sandbox version. If you did the original pull from git instead of the dev snapshot, you'd be able to create a patch with a single command line statement...

http://drupal.org/node/707484

git diff > [description]-[issue-number]-[comment-number].patch

Even if your host doesn't support git, you can still use it from your local machine. Instead of downloading the dev snapshot over HTTP, follow the instructions in each modules Version Control tab.

http://drupal.org/project/1222620/git-instructions

After you've downloaded the module with git, upload it to your host. Make your changes the same way you've always made them then download the changed files into the local directory. Use git diff to create a patch.

An enormous amount of effort went into migrating from CVS to Git. It only takes a few hours to master the basics and saves other developers hours trying to merge code snippets from comments back into modules.

pumpkinkid’s picture

sub

rogical’s picture

+1 very much need in D7

bryancasler’s picture

subscribe

BeaPower’s picture

sub

patoshi’s picture

im trying to do a git clone, but is it just me that i cant find the URL of the git repo? still new to git... usually there is a url to clone. thanks!

nvm i got it, but im getting this error upon install:

Fatal error: Call to undefined function rules_events_global_user_argument() in /home/xxx/public_html/dev/sites/all/modules/user_stats/user_stats.rules.inc on line 74

nvm again... =) this was just a old follow up. didnt read the other posts.. ignore this.

jbova’s picture

The latest version from git repo works great. Thanks.

jbova’s picture

Well, I didn't have the latest version at first and had to fix the stats increment functions. I see that was done in the latest 7.x-1.x branch. Downloaded that branch and made some changes. COMMENT_PUBLISHED status was changed to 1 in D7, and COMMENT_UNPUBLISHED is now 0. This was to stay consistent with the node constants.

The hook_*_*_OLD functions have been removed and new hooks for nodes and comments have been added. Fixed a few db_query calls to work with D7. Fixed a missing ":" in one of the db_query params.

trillex’s picture

sub

Babalu’s picture

subscribing

Canadaka’s picture

subscribing

johnatwork’s picture

subscribed

thomas1977’s picture

Subscribe. Highly needed.

Liam McDermott’s picture

I'm short on time, but have just created a Drupal 7 branch and (hopefully) committed the work you wonderful people have done so far. :)

Would someone mind checking it works? Then I'll make the -dev branch available for wider testing. Thanks very much for the contributions so far!

jbova’s picture

FileSize
4.21 KB

Liam,

This looks great so far. There is still one critical outstanding issue, the rules integration. This causes the module installation to fail completely and throw the error "Call to undefined function rules_events_global_user_argument".

It seems that this additional array data, which sets the active user, can be removed. I have attached a diff.

I believe the module needs to be disabled, uninstalled, and then reinstalled after making these changes for it to work.

diff --git a/user_stats.rules.inc b/user_stats.rules.inc
index b35788b..b722cb1 100644
--- a/user_stats.rules.inc
+++ b/user_stats.rules.inc
@@ -10,54 +10,50 @@
  * @ingroup rules
  */
 function user_stats_rules_event_info() {
+  $defaults = array(
+    'group' => t('User Stats'),
+    'module' => 'User Stats',
+  );
   return array(
-    'user_stats_login_count_increment' => array(
+    'user_stats_login_count_increment' => $defaults + array(
       'label' => t('User login count increased'),
-      'module' => 'User Stats',
-      'arguments' => user_stats_rules_events_arguments(),
+      'variables' => user_stats_rules_events_variables(),
     ),
-    'user_stats_login_count_decrement' => array(
+    'user_stats_login_count_decrement' => $defaults + array(
       'label' => t('User login count decreased'),
-      'module' => 'User Stats',
-      'arguments' => user_stats_rules_events_arguments(),
+      'variables' => user_stats_rules_events_variables(),
     ),
-    'user_stats_login_count_reset' => array(
+    'user_stats_login_count_reset' => $defaults + array(
       'label' => t('User login count reset'),
-      'module' => 'User Stats',
-      'arguments' => user_stats_rules_events_arguments(),
+      'variables' => user_stats_rules_events_variables(),
     ),
-    'user_stats_post_count_increment' => array(
+    'user_stats_post_count_increment' => $defaults + array(
       'label' => t('User post count increased'),
-      'module' => 'User Stats',
-      'arguments' => user_stats_rules_events_arguments(),
+      'variables' => user_stats_rules_events_variables(),
     ),
-    'user_stats_post_count_decrement' => array(
+    'user_stats_post_count_decrement' => $defaults + array(
       'label' => t('User post count decreased'),
-      'module' => 'User Stats',
-      'arguments' => user_stats_rules_events_arguments(),
+      'variables' => user_stats_rules_events_variables(),
     ),
-    'user_stats_post_count_reset' => array(
+    'user_stats_post_count_reset' => $defaults + array(
       'label' => t('User post count reset'),
-      'module' => 'User Stats',
-      'arguments' => user_stats_rules_events_arguments(),
+      'variables' => user_stats_rules_events_variables(),
     ),
-    'user_stats_ip_address_insert' => array(
+    'user_stats_ip_address_insert' => $defaults + array(
       'label' => t('User has a new IP address'),
-      'module' => 'User Stats',
-      'arguments' => user_stats_rules_events_arguments(),
+      'variables' => user_stats_rules_events_variables(),
     ),
-    'user_stats_day_older' => array(
+    'user_stats_day_older' => $defaults + array(
       'label' => t('User is a day older'),
-      'module' => 'User Stats',
-      'arguments' => user_stats_rules_events_arguments_day_older(),
+      'variables' => user_stats_rules_events_variables_day_older(),
     ),
   );
 }
 
 /**
- * Defines arguments for user_stats_rules_event_info().
+ * Defines variables for user_stats_rules_event_info().
  */
-function user_stats_rules_events_arguments() {
+function user_stats_rules_events_variables() {
   return array(
     'uid' => array(
       'type' => 'number',
@@ -71,21 +67,22 @@ function user_stats_rules_events_arguments() {
       'type' => 'user',
       'label' => t("User who's statistics have changed"),
       'handler' => 'user_stats_events_argument_user',
-    ) + rules_events_global_user_argument(),
+    ) //+ rules_events_global_user_argument(),
+    // ^ Do we need to set the acting user?
   );
 }
 
 /**
- * Defines arguments for user_stats_rules_event_info().
+ * Defines variables for user_stats_rules_event_info().
  *
- * The arguments for a day_older event are slightly different to other items.
+ * The variables for a day_older event are slightly different to other items.
  */
-function user_stats_rules_events_arguments_day_older() {
-  // Get the default arguments.
-  $arguments = user_stats_rules_events_arguments();
-  $arguments['statistic_value']['handler'] = 'user_stats_events_argument_day_older';
+function user_stats_rules_events_variables_day_older() {
+  // Get the default variables.
+  $variables = user_stats_rules_events_variables();
+  $variables['statistic_value']['handler'] = 'user_stats_events_argument_day_older';
 
-  return $arguments;
+  return $variables;
 }
 
 /**
Liam McDermott’s picture

Title: Port user stats to Drupal 7 » User Stats for Drupal 7
Status: Active » Fixed

Thanks, committed.

We can deal with anything else in separate issues.

andypost’s picture

Status: Fixed » Reviewed & tested by the community

Please roll-out 7.x-dev release? Also please add Version tag for issues

Liam McDermott’s picture

Status: Reviewed & tested by the community » Fixed

Please roll-out 7.x-dev release? Also please add Version tag for issues

It takes a while from creating a dev release to Drupal creating the file and publishing the release. I also forgot to go and check the option to show a 7.x -dev snapshot on the project page (it was still available under All releases though).

I think the version tag also appears when the project node is automatically published by drupal.org, it's there now and I didn't have to do anything extra.

Should all be working now, though. :)

Status: Fixed » Closed (fixed)
Issue tags: -d7 ports

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