Index: kernel/classes/ezurlaliasml.php
===================================================================
--- kernel/classes/ezurlaliasml.php	(revision 22645)
+++ 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_id" );
+        return $def;
+    }
+
+}
+?>

Property changes on: kernel\classes\ezurlaliasmlid.php
___________________________________________________________________
Added: svn:eol-style
   + native

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,48 @@
+#!/usr/bin/env php
+<?php
+
+require 'autoload.php';
+
+$cli = eZCLI::instance();
+
+$scriptSettings = array();
+$scriptSettings['description'] = 'your description of this script comes here';
+$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_id table' );
+$db->query( 'TRUNCATE TABLE ezurlalias_ml_id' );
+
+$cli->output( 'Setting next auto_increment value to highest existing ID + 1' );
+$db->query( "ALTER TABLE ezurlalias_ml_id AUTO_INCREMENT=$autoInc" );
+
+$cli->output( 'Inserting existing IDs into ezurlalias_ml_id table' );
+$db->query( "INSERT INTO ezurlalias_ml_id (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

