From 7d5fb915385f5697d1cd73421021fe11e11a188d Mon Sep 17 00:00:00 2001
From: Marco Villegas <marvil07@gmail.com>
Date: Sun, 13 Feb 2011 11:22:15 -0500
Subject: [PATCH] feature #1055504: Use timestamp for {versioncontrol_repositories}.locked field.

---
 includes/VersioncontrolRepository.php              |   13 ++++++++++++-
 ...ntrol_handler_field_repository_manual_fetch.inc |    7 +++----
 versioncontrol.admin.inc                           |    2 +-
 versioncontrol.install                             |    2 +-
 4 files changed, 17 insertions(+), 7 deletions(-)

diff --git includes/VersioncontrolRepository.php includes/VersioncontrolRepository.php
index f54b079..c1aa168 100644
--- includes/VersioncontrolRepository.php
+++ includes/VersioncontrolRepository.php
@@ -63,7 +63,8 @@ abstract class VersioncontrolRepository implements VersioncontrolEntityInterface
   public $updated = 0;
 
   /**
-   * Indicates if the repository is being updated now.
+   * Timestamp of the last time the repository has been locked.
+   * Lock means the repository is being updated.
    *
    * @var    integer
    */
@@ -126,6 +127,16 @@ abstract class VersioncontrolRepository implements VersioncontrolEntityInterface
   }
 
   /**
+   * Conviniece method to set the lock to a specific value.
+   */
+  public function updateLocked($timestamp = NULL) {
+    if (is_null($timestamp)) {
+      $timestamp = time();
+    }
+    $this->locked = $timestamp;
+  }
+
+  /**
    * Pseudo-constructor method; call this method with an associative array or
    * stdClass object containing properties to be assigned to this object.
    *
diff --git includes/views/handlers/versioncontrol_handler_field_repository_manual_fetch.inc includes/views/handlers/versioncontrol_handler_field_repository_manual_fetch.inc
index e2fa109..f8c7b48 100644
--- includes/views/handlers/versioncontrol_handler_field_repository_manual_fetch.inc
+++ includes/views/handlers/versioncontrol_handler_field_repository_manual_fetch.inc
@@ -19,8 +19,8 @@ class versioncontrol_handler_field_repository_manual_fetch extends views_handler
   }
 
   function render($values) {
-    $is_locked = $values->{$this->locked_alias};
-    if (empty($is_locked)) {
+    $locked = $values->{$this->locked_alias};
+    if ($locked == 0) {
       $link = array(
         'title' => t('Fetch logs'),
         'href' => 'admin/content/versioncontrol-repositories/fetch/' . $values->{$this->repo_alias},
@@ -33,8 +33,7 @@ class versioncontrol_handler_field_repository_manual_fetch extends views_handler
         'href' => 'admin/content/versioncontrol-repositories/clearlock/' . $values->{$this->repo_alias},
       );
       $output = theme('links', array($link));
-      return  t('Repo is locked.') . "($output)";
-
+      return  t('Repo is locked since @date.', array('@date' => format_date($locked, 'small'))) . "($output)";
     }
   }
 }
diff --git versioncontrol.admin.inc versioncontrol.admin.inc
index 0deb6a7..4277c14 100644
--- versioncontrol.admin.inc
+++ versioncontrol.admin.inc
@@ -596,7 +596,7 @@ function versioncontrol_admin_repository_clearlock_confirm_submit($form, &$form_
   $backend = versioncontrol_get_backends($form_state['backend']);
   $repository = $backend->loadEntity('repo', array($form_state['repo_id']));
 
-  $repository->locked = FALSE;
+  $repository->locked = 0;
   $repository->update();
   $form_state['redirect'] = 'admin/content/versioncontrol-repositories';
 }
diff --git versioncontrol.install versioncontrol.install
index 79be207..e919e15 100644
--- versioncontrol.install
+++ versioncontrol.install
@@ -344,7 +344,7 @@ function versioncontrol_schema() {
         'default' => 1
       ),
       'locked' => array(
-        'description' => 'Dead-simple semaphore - boolean indicating whether the repository is unlocked (0) or locked (1). Locking is typically used when doing log fetches.',
+        'description' => 'Timestamp indicating the last time the repository was locked when doing log fetches or 0 when not locked.',
         'type' => 'int',
         'not null' => TRUE,
         'default' => 0,
-- 
1.7.2.3

