public function testSetLangMaskAlwaysAvailable()
 {
     $nodeID = mt_rand();
     // Create an ezurlalias_ml entry
     $url = eZURLAliasML::create(__FUNCTION__ . $nodeID, "eznode:" . $nodeID, 0, 2);
     $url->store();
     // Update lang_mask by setting always available,
     eZURLAliasML::setLangMaskAlwaysAvailable(2, "eznode", $nodeID);
     // Verify that language mask was increased to 3.
     $urls = eZURLAliasML::fetchByAction('eznode', $nodeID);
     self::assertEquals(3, (int) $urls[0]->attribute('lang_mask'));
     // Update lang_mask by removing always available,
     eZURLAliasML::setLangMaskAlwaysAvailable(false, "eznode", $nodeID);
     // Verify that language mask was reduced back to 2.
     $urls = eZURLAliasML::fetchByAction('eznode', $nodeID);
     self::assertEquals(2, (int) $urls[0]->attribute('lang_mask'));
 }
    /**
     * @param int $languageID
     * @param int|bool $version
     */
    function setAlwaysAvailableLanguageID( $languageID, $version = false )
    {
        $db = eZDB::instance();
        $db->begin();

        if ( $version == false )
        {
            $version = $this->currentVersion();
            if ( $languageID )
            {
                $this->setAttribute( 'language_mask', (int)$this->attribute( 'language_mask' ) | 1 );
            }
            else
            {
                $this->setAttribute( 'language_mask', (int)$this->attribute( 'language_mask' ) & ~1 );
            }
            $this->store();
        }

        $objectID = $this->attribute( 'id' );
        $versionID = $version->attribute( 'version' );

        // reset 'always available' flag
        $sql = "UPDATE ezcontentobject_name SET language_id=";
        if ( $db->databaseName() == 'oracle' )
        {
            $sql .= "bitand( language_id, -2 )";
        }
        else
        {
            $sql .= "language_id & ~1";
        }
        $sql .= " WHERE contentobject_id = '$objectID' AND content_version = '$versionID'";
        $db->query( $sql );

        if ( $languageID != false )
        {
            $newLanguageID = $languageID | 1;
            $sql = "UPDATE ezcontentobject_name
                    SET language_id='$newLanguageID'
                    WHERE language_id='$languageID' AND contentobject_id = '$objectID' AND content_version = '$versionID'";
            $db->query( $sql );
        }

        $version->setAlwaysAvailableLanguageID( $languageID );

        // Update url alias for all locations
        $nodeRows = eZContentObjectTreeNode::fetchByContentObjectID( $objectID, false );
        $actions = array();
        foreach ( $nodeRows as $nodeRow )
        {
            $nodeID = (int)$nodeRow['node_id'];
            $actions[] = array( 'eznode', $nodeID );
        }
        eZURLAliasML::setLangMaskAlwaysAvailable( $languageID, $actions, null );

        $db->commit();
    }