Changeset 5267


Ignore:
Timestamp:
Mar 12, 2010, 8:59:58 AM (12 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1463: HTTP Status 500 when logging in

Added update scripts that removes the bad 'null' values in the sort_property column.

Made the menu script more robust in case an error occurs.

NOTE! This update conflicts with the schema version change in the trunk for #1442 [5260]. This needs to be fixed in the trunk when we have merged 2.15 back to it.

Location:
branches/2.15-stable
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/2.15-stable/src/core/common-queries.xml

    r5185 r5267  
    36433643    </description>
    36443644  </query>
     3645  <query id="FIX_NULL_IN_CONTEXTS_SORT_PROPERTY" type="SQL">
     3646    <sql>
     3647      update [Contexts]
     3648      set [sort_property] = null
     3649      where [sort_property] like '%null%'
     3650    </sql>
     3651    <description>
     3652      An SQL query that replaces all 'null' strings in Context.sort_property with
     3653      null values.
     3654    </description>
     3655  </query>
    36453656
    36463657</predefined-queries>
  • branches/2.15-stable/src/core/net/sf/basedb/core/Install.java

    r5265 r5267  
    114114    method.
    115115  */
    116   public static final int NEW_SCHEMA_VERSION = Integer.valueOf(78).intValue();
     116  public static final int NEW_SCHEMA_VERSION = Integer.valueOf(79).intValue();
    117117 
    118118  public static synchronized void createTables(boolean update, final ProgressReporter progress)
  • branches/2.15-stable/src/core/net/sf/basedb/core/Update.java

    r5248 r5267  
    865865    </td>
    866866  </tr>
     867  <tr>
     868    <td>79</td>
     869    <td>
     870      Set database column Contexts.sort_property to null if it contains a literal
     871      'null' string. Fix for #1463.
     872    </td>
     873  </tr>
    867874  </table>
    868875
     
    11731180        if (progress != null) progress.display((int)(77*progress_factor), "--Updating schema version: " + schemaVersion + " -> 78...");
    11741181        schemaVersion = setSchemaVersionInTransaction(session, 78);
     1182      }
     1183     
     1184      if (schemaVersion < 79)
     1185      {
     1186        if (progress != null) progress.display((int)(78*progress_factor),
     1187            "--Updating schema version: " + schemaVersion + " -> 79...");
     1188        schemaVersion = updateToSchemaVersion79(session);
    11751189      }
    11761190
     
    27202734      if (tx != null) HibernateUtil.rollback(tx);
    27212735      log.error("updateToSchemaVersion77: FAILED", ex);
     2736      throw ex;
     2737    }
     2738    return schemaVersion;
     2739  }
     2740
     2741 
     2742  /**
     2743    Set sort_property in Contexts table to null if it contains a literal string 'null'.
     2744  */
     2745  private static int updateToSchemaVersion79(org.hibernate.Session session)
     2746    throws BaseException
     2747  {
     2748    final int schemaVersion = 79;
     2749    org.hibernate.Transaction tx = null;
     2750    try
     2751    {
     2752      tx = HibernateUtil.newTransaction(session);
     2753     
     2754      // Change property values
     2755      // Load all annotation sets with a null id
     2756      org.hibernate.Query query = HibernateUtil.getPredefinedSQLQuery(session,
     2757          "FIX_NULL_IN_CONTEXTS_SORT_PROPERTY");
     2758      /*
     2759        update [Contexts]
     2760        set [sort_property] = null
     2761        where [sort_property] like '%null%'
     2762      */
     2763      query.executeUpdate();
     2764     
     2765      // Update the schema version number
     2766      setSchemaVersion(session, schemaVersion);
     2767
     2768      // Commit the changes
     2769      HibernateUtil.commit(tx);
     2770      log.info("updateToSchemaVersion79: OK");
     2771    }
     2772    catch (BaseException ex)
     2773    {
     2774      if (tx != null) HibernateUtil.rollback(tx);
     2775      log.error("updateToSchemaVersion79: FAILED", ex);
    27222776      throw ex;
    27232777    }
  • branches/2.15-stable/www/include/menu.jsp

    r5256 r5267  
    8585{
    8686  // Projects menu
    87   final ItemContext projectCC = sc.getCurrentContext(Item.PROJECT);
    8887  int activeProjectId = sc.getActiveProjectId();
    89   final ItemQuery<Project> projectQuery = Project.getQuery();
    90   projectQuery.include(Include.MINE, Include.SHARED);
    91   Order projectSortOrder = projectCC.getSortOrder();
    92   if (projectSortOrder != null) projectQuery.order(projectSortOrder);
    93   projectQuery.order(Orders.asc(Hql.property("name")));
    94   projectQuery.setCacheResult(true);
    95   final DbControl dc = sc.newDbControl();
    96   try
    97   {
    98     %>
    99     <m:menu 
    100       id="projects"
    101       style="display: none"
    102       >
    103       <m:menuitem
    104         title="<i>- no active project -</i>"
    105         onclick="<%="Main.openPopup('"+root+"my_base/projects/set_active.jsp?ID="+ID+"', 'ActivateProject', 300, 140)"%>"
    106         icon="<%=activeProjectId == 0 ? "checkedmenu.gif" : null%>"
    107         enabled="<%=activeProjectId != 0%>"
    108         tooltip="<%=activeProjectId == 0 ? "No project is active" : "Disable the currently active project"%>"
    109       />
    110       <%
     88  %>
     89  <m:menu 
     90    id="projects"
     91    style="display: none"
     92    >
     93    <m:menuitem
     94      title="<i>- no active project -</i>"
     95      onclick="<%="Main.openPopup('"+root+"my_base/projects/set_active.jsp?ID="+ID+"', 'ActivateProject', 300, 140)"%>"
     96      icon="<%=activeProjectId == 0 ? "checkedmenu.gif" : null%>"
     97      enabled="<%=activeProjectId != 0%>"
     98      tooltip="<%=activeProjectId == 0 ? "No project is active" : "Disable the currently active project"%>"
     99    />
     100    <%
     101    final DbControl dc = sc.newDbControl();
     102    try
     103    {
     104      final ItemContext projectCC = sc.getCurrentContext(Item.PROJECT);
     105      final ItemQuery<Project> projectQuery = Project.getQuery();
     106      projectQuery.include(Include.MINE, Include.SHARED);
     107      Order projectSortOrder = projectCC.getSortOrder();
     108      if (projectSortOrder != null) projectQuery.order(projectSortOrder);
     109      projectQuery.order(Orders.asc(Hql.property("name")));
     110      projectQuery.setCacheResult(true);
    111111      ItemResultList<Project> projects = projectQuery.list(dc);
    112112      boolean breakAt20 = projects.size() > 25;
     
    141141        <%
    142142      }
     143    }
     144    catch (Throwable t)
     145    {
     146      t.printStackTrace();
    143147      %>
    144     </m:menu>
    145     <%
    146   }
    147   finally
    148   {
    149     if (dc != null) dc.close();
    150   }
     148      <m:menuitem
     149        title="Error loading projects"
     150        tooltip="<%=t.getMessage() + ": Check log file for more details"%>"
     151        enabled="false"
     152        icon="error.gif"
     153      />
     154      <%
     155    }
     156    finally
     157    {
     158      if (dc != null) dc.close();
     159    }
     160    %>
     161  </m:menu>
     162  <%
    151163}
    152164else if ("recentItems".equals(name) && sc != null && sc.isLoggedIn())
Note: See TracChangeset for help on using the changeset viewer.