### Eclipse Workspace Patch 1.0
#P WineAlley
Index: src/vendor/ezsystems/ezpublish/eZ/Publish/Core/Persistence/Legacy/Content/Gateway/EzcDatabase.php
===================================================================
--- src/vendor/ezsystems/ezpublish/eZ/Publish/Core/Persistence/Legacy/Content/Gateway/EzcDatabase.php	(revision 2328)
+++ src/vendor/ezsystems/ezpublish/eZ/Publish/Core/Persistence/Legacy/Content/Gateway/EzcDatabase.php	(working copy)
@@ -405,9 +405,21 @@
             ->update( $this->dbHandler->quoteTable( 'ezcontentobject_name' ) )
             ->set(
                 $this->dbHandler->quoteColumn( 'language_id' ),
-                $newAlwaysAvailable
-                    ? $qName->expr->bitOr( $this->dbHandler->quoteColumn( 'language_id' ), 1 )
-                    : $qName->expr->bitAnd( $this->dbHandler->quoteColumn( 'language_id' ), -2 )
+                $qName->expr->sub(
+                    $qName->expr->bitOr(
+                        $qName->expr->bitAnd( $this->dbHandler->quoteColumn( 'language_id' ), -2 ),
+                        $qName->bindValue( $newAlwaysAvailable, null, \PDO::PARAM_INT )
+                    ),
+                    sprintf(
+                        '( %s )',
+                        $qName->expr->eq(
+                            $qName->expr->bitAnd(
+                                $this->dbHandler->quoteColumn( 'language_id' ),
+                                $qName->bindValue( $contentInfoRow['initial_language_id'], null, \PDO::PARAM_INT ) ),
+                            0
+                        )
+                    )
+                )
             )
             ->where(
                 $qName->expr->lAnd(
@@ -434,9 +446,21 @@
             ->update( $this->dbHandler->quoteTable( 'ezcontentobject_attribute' ) )
             ->set(
                 $this->dbHandler->quoteColumn( 'language_id' ),
-                $newAlwaysAvailable
-                    ? $qAttr->expr->bitOr( $this->dbHandler->quoteColumn( 'language_id' ), 1 )
-                    : $qAttr->expr->bitAnd( $this->dbHandler->quoteColumn( 'language_id' ), -2 )
+                $qAttr->expr->sub(
+                    $qAttr->expr->bitOr(
+                        $qAttr->expr->bitAnd( $this->dbHandler->quoteColumn( 'language_id' ), -2 ),
+                        $qAttr->bindValue( $newAlwaysAvailable, null, \PDO::PARAM_INT )
+                    ),
+                    sprintf(
+                        '( %s )',
+                        $qAttr->expr->eq(
+                            $qAttr->expr->bitAnd(
+                                $this->dbHandler->quoteColumn( 'language_id' ),
+                                $qAttr->bindValue( $contentInfoRow['initial_language_id'], null, \PDO::PARAM_INT ) ),
+                            0
+                        )
+                    )
+                )
             )
             ->where(
                 $qAttr->expr->lAnd(
@@ -1214,6 +1238,7 @@
      */
     public function setName( $contentId, $version, $name, $language )
     {
+        $contentInfoRow = $this->loadContentInfo( $contentId );
         $language = $this->languageHandler->loadByLanguageCode( $language );
 
         // Is it an insert or an update ?
@@ -1251,6 +1276,12 @@
             );
         }
 
+        // Set the always available bit if necessary
+        $languageId = $language->id;
+        if ( $contentInfoRow['language_mask'] & 1 && $languageId == $contentInfoRow['initial_language_id'] )
+        {
+            $languageId |= 1; // set the always available bit
+        }
         $q->set(
             $this->dbHandler->quoteColumn( 'contentobject_id' ),
             $q->bindValue( $contentId, null, \PDO::PARAM_INT )
@@ -1259,7 +1290,7 @@
             $q->bindValue( $version, null, \PDO::PARAM_INT )
         )->set(
             $this->dbHandler->quoteColumn( 'language_id' ),
-            $q->bindValue( $language->id, null, \PDO::PARAM_INT )
+            $q->bindValue( $languageId, null, \PDO::PARAM_INT )
         )->set(
             $this->dbHandler->quoteColumn( 'content_translation' ),
             $q->bindValue( $language->languageCode )
