Index: kernel/classes/ezurlaliasml.php
===================================================================
--- kernel/classes/ezurlaliasml.php	(revision 22686)
+++ kernel/classes/ezurlaliasml.php	(working copy)
@@ -237,18 +237,11 @@
     */
     function store( $fieldFilters = null )
     {
-        $locked = false;
         if ( $this->ID === null )
         {
-            $locked = true;
-            $db = eZDB::instance();
-            $db->lock( "ezurlalias_ml" );
-            $query = "SELECT max( id ) + 1 AS id FROM ezurlalias_ml";
-            $rows = $db->arrayQuery( $query );
-            $id = (int)$rows[0]['id'];
-            if ( $id == 0 )
-                $id = 1;
-            $this->ID = $id;
+            $id = new eZURLAliasMlID( array() );
+            $id->store();
+            $this->ID = $id->attribute( 'id' );
         }
         if ( $this->Link === null )
         {
@@ -272,10 +265,6 @@
         }
 
         eZPersistentObject::store( $fieldFilters );
-        if ( $locked )
-        {
-            $db->unlock();
-        }
     }
 
     /*!
@@ -613,13 +602,9 @@
                 $idtmp = (int)$row['id'];
                 if ( $idtmp == $newElementID )
                 {
-                    $db->lock( "ezurlalias_ml" );
-                    $query = "SELECT max( id ) + 1 AS id FROM ezurlalias_ml";
-                    $rowstmp = $db->arrayQuery( $query );
-                    $idtmp = (int)$rowstmp[0]['id'];
-                    if ( $idtmp == 0 )
-                        $idtmp = 1;
-                    $db->unlock();
+                    $id = new eZURLAliasMlID( array() );
+                    $id->store();
+                    $idtmp = $id->attribute( 'id' );
                 }
                 $parentIDTmp = (int)$row['parent'];
                 $textMD5Tmp = eZURLALiasML::md5( $db, $row['text'] );
Index: kernel/classes/ezurlaliasmlid.php
===================================================================
--- kernel/classes/ezurlaliasmlid.php	(revision 0)
+++ kernel/classes/ezurlaliasmlid.php	(revision 0)
@@ -0,0 +1,26 @@
+<?php
+// Persistent object class auto-generated
+
+class eZURLAliasMlID extends eZPersistentObject
+{
+    function __construct( $row )
+    {
+        $this->eZPersistentObject( $row );
+    }
+
+    static function definition()
+    {
+        $def = array( "fields" => array( "id" => array( "name" => "id",
+                                                        "datatype" => "integer",
+                                                        "required" => false ) ),
+                      "keys" => array( "id" ),
+                      "function_attributes" => array(),
+                      "increment_key" => "id",
+                      "class_name" => "eZURLAliasMlID",
+                      "sort" => array(),
+                      "name" => "ezurlalias_ml_incr" );
+        return $def;
+    }
+
+}
+?>

Property changes on: kernel\classes\ezurlaliasmlid.php
___________________________________________________________________
Added: svn:eol-style
   + native

Index: kernel/sql/mysql/kernel_schema.sql
===================================================================
--- kernel/sql/mysql/kernel_schema.sql	(revision 22686)
+++ kernel/sql/mysql/kernel_schema.sql	(working copy)
@@ -1481,6 +1481,15 @@
 
 
 
+CREATE TABLE ezurlalias_ml_incr (
+  id int(11) NOT NULL auto_increment,
+  PRIMARY KEY  (id)
+) TYPE=InnoDB;
+
+
+
+
+
 CREATE TABLE ezurlwildcard (
   destination_url longtext NOT NULL,
   id int(11) NOT NULL auto_increment,
@@ -1560,8 +1569,8 @@
   current_visit_timestamp int(11) NOT NULL default '0',
   failed_login_attempts int(11) NOT NULL default '0',
   last_visit_timestamp int(11) NOT NULL default '0',
+  login_count int(11) NOT NULL default '0',
   user_id int(11) NOT NULL default '0',
-  login_count int(11) NOT NULL default '0',
   PRIMARY KEY  (user_id),
   KEY ezuservisit_co_visit_count (current_visit_timestamp,login_count)
 ) TYPE=InnoDB;
Index: kernel/sql/postgresql/kernel_schema.sql
===================================================================
--- kernel/sql/postgresql/kernel_schema.sql	(revision 22686)
+++ kernel/sql/postgresql/kernel_schema.sql	(working copy)
@@ -919,6 +919,19 @@
 
 
 
+CREATE SEQUENCE ezurlalias_ml_incr_s
+    START 1
+    INCREMENT 1
+    MAXVALUE 9223372036854775807
+    MINVALUE 1
+    CACHE 1;
+
+
+
+
+
+
+
 CREATE SEQUENCE ezurlwildcard_s
     START 1
     INCREMENT 1
@@ -2542,6 +2555,16 @@
 
 
 
+CREATE TABLE ezurlalias_ml_incr (
+    id integer DEFAULT nextval('ezurlalias_ml_incr_s'::text) NOT NULL
+);
+
+
+
+
+
+
+
 CREATE TABLE ezurlwildcard (
     destination_url text NOT NULL,
     id integer DEFAULT nextval('ezurlwildcard_s'::text) NOT NULL,
@@ -2625,8 +2648,8 @@
     current_visit_timestamp integer DEFAULT 0 NOT NULL,
     failed_login_attempts integer DEFAULT 0 NOT NULL,
     last_visit_timestamp integer DEFAULT 0 NOT NULL,
-    user_id integer DEFAULT 0 NOT NULL,
-    login_count integer DEFAULT 0 NOT NULL
+    login_count integer DEFAULT 0 NOT NULL,
+    user_id integer DEFAULT 0 NOT NULL
 );
 
 
@@ -4655,6 +4678,15 @@
 
 
 
+ALTER TABLE ONLY ezurlalias_ml_incr
+    ADD CONSTRAINT ezurlalias_ml_incr_pkey PRIMARY KEY (id);
+
+
+
+
+
+
+
 ALTER TABLE ONLY ezurlwildcard
     ADD CONSTRAINT ezurlwildcard_pkey PRIMARY KEY (id);
 
Index: share/db_schema.dba
===================================================================
--- share/db_schema.dba	(revision 22686)
+++ share/db_schema.dba	(working copy)
@@ -6712,6 +6712,29 @@
       ),
     ),
   ),
+  'ezurlalias_ml_incr' => 
+  array (
+    'name' => 'ezurlalias_ml_incr',
+    'fields' => 
+    array (
+      'id' => 
+      array (
+        'type' => 'auto_increment',
+        'default' => false,
+      ),
+    ),
+    'indexes' => 
+    array (
+      'PRIMARY' => 
+      array (
+        'type' => 'primary',
+        'fields' => 
+        array (
+          0 => 'id',
+        ),
+      ),
+    ),
+  ),
   'ezurlwildcard' => 
   array (
     'name' => 'ezurlwildcard',
@@ -7019,14 +7042,14 @@
         'not_null' => '1',
         'default' => 0,
       ),
-      'user_id' => 
+      'login_count' => 
       array (
         'length' => 11,
         'type' => 'int',
         'not_null' => '1',
         'default' => 0,
       ),
-      'login_count' => 
+      'user_id' => 
       array (
         'length' => 11,
         'type' => 'int',
@@ -7810,4 +7833,4 @@
   ),
 );
 
-?>
+?>
\ No newline at end of file
Index: update/common/scripts/4.1/initurlaliasmlid.php
===================================================================
--- update/common/scripts/4.1/initurlaliasmlid.php	(revision 0)
+++ update/common/scripts/4.1/initurlaliasmlid.php	(revision 0)
@@ -0,0 +1,57 @@
+#!/usr/bin/env php
+<?php
+
+require 'autoload.php';
+
+$cli = eZCLI::instance();
+
+$scriptSettings = array();
+$scriptSettings['description'] = 'Initialize the ezurlalias_ml_incr table';
+$scriptSettings['use-session'] = true;
+$scriptSettings['use-modules'] = true;
+$scriptSettings['use-extensions'] = true;
+
+$script = eZScript::instance( $scriptSettings );
+$script->startup();
+
+$config = '';
+$argumentConfig = '';
+$optionHelp = false;
+$arguments = false;
+$useStandardOptions = true;
+
+$options = $script->getOptions( $config, $argumentConfig, $optionHelp, $arguments, $useStandardOptions );
+$script->initialize();
+
+include_once( 'kernel/classes/ezurlaliasmlid.php' );
+
+$db = eZDB::instance();
+
+$maxIDs = $db->arrayQuery( 'SELECT MAX( id ) AS max_id FROM ezurlalias_ml', array( 'column' => 'max_id' ) );
+
+$maxID = (int)$maxIDs[0];
+$cli->output( "highest ID in ezurlalias_ml table: $maxID" );
+
+$autoInc = $maxID + 1;
+
+$cli->output( 'Truncating ezurlalias_ml_incr table' );
+$db->query( 'TRUNCATE TABLE ezurlalias_ml_incr' );
+
+$cli->output( 'Setting next auto_increment value to highest existing ID + 1' );
+
+if ( $db instanceof eZMySQLDB || $db instanceof eZMySQLiDB )
+{
+    $db->query( "ALTER TABLE ezurlalias_ml_incr AUTO_INCREMENT=$autoInc" );
+}
+else
+{
+    $db->query( "DROP SEQUENCE ezurlalias_ml_incr_s" );
+    $db->query( "CREATE SEQUENCE ezurlalias_ml_incr_s MINVALUE $autoInc" );
+}
+
+$cli->output( 'Inserting existing IDs into ezurlalias_ml_incr table' );
+$db->query( "INSERT INTO ezurlalias_ml_incr (id) SELECT DISTINCT id FROM ezurlalias_ml" );
+
+$script->shutdown( 0 );
+
+?>
\ No newline at end of file

Property changes on: update\common\scripts\4.1\initurlaliasmlid.php
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:eol-style
   + native

