1 31 32 package org.opencms.db.generic; 33 34 import org.opencms.configuration.CmsConfigurationManager; 35 import org.opencms.db.CmsDbContext; 36 import org.opencms.db.CmsDbEntryNotFoundException; 37 import org.opencms.db.CmsDbSqlException; 38 import org.opencms.db.CmsDbUtil; 39 import org.opencms.db.CmsDriverManager; 40 import org.opencms.db.CmsPublishList; 41 import org.opencms.db.CmsPublishedResource; 42 import org.opencms.db.I_CmsDriver; 43 import org.opencms.db.I_CmsProjectDriver; 44 import org.opencms.file.CmsDataAccessException; 45 import org.opencms.file.CmsFile; 46 import org.opencms.file.CmsFolder; 47 import org.opencms.file.CmsGroup; 48 import org.opencms.file.CmsProject; 49 import org.opencms.file.CmsProperty; 50 import org.opencms.file.CmsResource; 51 import org.opencms.file.CmsResourceFilter; 52 import org.opencms.file.CmsUser; 53 import org.opencms.file.CmsVfsResourceAlreadyExistsException; 54 import org.opencms.file.CmsVfsResourceNotFoundException; 55 import org.opencms.file.types.CmsResourceTypeFolder; 56 import org.opencms.i18n.CmsMessageContainer; 57 import org.opencms.main.CmsEvent; 58 import org.opencms.main.CmsException; 59 import org.opencms.main.CmsLog; 60 import org.opencms.main.I_CmsEventListener; 61 import org.opencms.main.OpenCms; 62 import org.opencms.report.I_CmsReport; 63 import org.opencms.security.I_CmsPrincipal; 64 import org.opencms.staticexport.CmsStaticExportManager; 65 import org.opencms.util.CmsStringUtil; 66 import org.opencms.util.CmsUUID; 67 import org.opencms.workflow.CmsTask; 68 import org.opencms.workflow.CmsTaskService; 69 70 import java.sql.Connection ; 71 import java.sql.PreparedStatement ; 72 import java.sql.ResultSet ; 73 import java.sql.SQLException ; 74 import java.util.ArrayList ; 75 import java.util.Collections ; 76 import java.util.HashSet ; 77 import java.util.Iterator ; 78 import java.util.List ; 79 import java.util.Map ; 80 import java.util.Set ; 81 82 import org.apache.commons.logging.Log; 83 84 95 public class CmsProjectDriver implements I_CmsDriver, I_CmsProjectDriver { 96 97 98 protected static final String TABLE_PROJECTS = "CMS_PROJECTS"; 99 100 101 private static final Log LOG = CmsLog.getLog(org.opencms.db.generic.CmsProjectDriver.class); 102 103 104 protected CmsDriverManager m_driverManager; 105 106 107 protected int[] m_maxIds; 108 109 110 protected org.opencms.db.generic.CmsSqlManager m_sqlManager; 111 112 115 public CmsProject createProject( 116 CmsDbContext dbc, 117 CmsUser owner, 118 CmsGroup group, 119 CmsGroup managergroup, 120 CmsTask task, 121 String name, 122 String description, 123 int flags, 124 int type, 125 Object reservedParam) throws CmsDataAccessException { 126 127 CmsProject project = null; 128 129 if ((description == null) || (description.length() < 1)) { 130 description = " "; 131 } 132 133 long createTime = System.currentTimeMillis(); 134 Connection conn = null; 135 PreparedStatement stmt = null; 136 137 int id = CmsDbUtil.UNKNOWN_ID; 138 139 try { 140 if (reservedParam == null) { 141 id = m_sqlManager.nextId(TABLE_PROJECTS); 143 conn = m_sqlManager.getConnection(dbc); 145 } else { 146 id = ((Integer )((Map )reservedParam).get("pkProjectId")).intValue(); 148 int projectId = ((Integer )((Map )reservedParam).get("projectId")).intValue(); 150 conn = m_sqlManager.getConnection(dbc, projectId); 151 } 152 153 stmt = m_sqlManager.getPreparedStatement(conn, "C_PROJECTS_CREATE"); 154 155 stmt.setInt(1, id); 156 stmt.setString(2, owner.getId().toString()); 157 stmt.setString(3, group.getId().toString()); 158 stmt.setString(4, managergroup.getId().toString()); 159 stmt.setInt(5, task.getId()); 160 stmt.setString(6, name); 161 stmt.setString(7, description); 162 stmt.setInt(8, flags); 163 stmt.setLong(9, createTime); 164 stmt.setInt(10, type); 165 stmt.executeUpdate(); 166 167 project = new CmsProject( 168 id, 169 name, 170 description, 171 task.getId(), 172 owner.getId(), 173 group.getId(), 174 managergroup.getId(), 175 flags, 176 createTime, 177 type); 178 } catch (SQLException e) { 179 throw new CmsDbSqlException(Messages.get().container( 180 Messages.ERR_GENERIC_SQL_1, 181 CmsDbSqlException.getErrorQuery(stmt)), e); 182 } finally { 183 m_sqlManager.closeAll(dbc, conn, stmt, null); 184 } 185 186 return project; 187 } 188 189 192 public void createProjectResource(CmsDbContext dbc, int projectId, String resourcePath, Object reservedParam) 193 throws CmsDataAccessException { 194 195 PreparedStatement stmt = null; 197 Connection conn = null; 198 199 boolean projectResourceExists = false; 200 try { 201 readProjectResource(dbc, projectId, resourcePath, reservedParam); 202 projectResourceExists = true; 203 } catch (CmsVfsResourceNotFoundException e) { 204 projectResourceExists = false; 206 } 207 208 if (projectResourceExists) { 209 throw new CmsVfsResourceAlreadyExistsException(Messages.get().container( 210 Messages.ERR_RESOURCE_WITH_NAME_ALREADY_EXISTS_1, 211 dbc.removeSiteRoot(resourcePath))); 212 } 213 214 try { 215 if (reservedParam == null) { 216 conn = m_sqlManager.getConnection(dbc); 218 } else { 219 conn = m_sqlManager.getConnection(dbc, ((Integer )reservedParam).intValue()); 221 } 222 223 stmt = m_sqlManager.getPreparedStatement(conn, "C_PROJECTRESOURCES_CREATE"); 224 225 stmt.setInt(1, projectId); 227 stmt.setString(2, resourcePath); 228 229 stmt.executeUpdate(); 230 } catch (SQLException e) { 231 throw new CmsDbSqlException(Messages.get().container( 232 Messages.ERR_GENERIC_SQL_1, 233 CmsDbSqlException.getErrorQuery(stmt)), e); 234 } finally { 235 m_sqlManager.closeAll(dbc, conn, stmt, null); 236 } 237 } 238 239 242 public void deleteAllStaticExportPublishedResources(CmsDbContext dbc, CmsProject currentProject, int linkType) 243 throws CmsDataAccessException { 244 245 Connection conn = null; 246 PreparedStatement stmt = null; 247 248 try { 249 conn = m_sqlManager.getConnection(dbc, currentProject.getId()); 250 stmt = m_sqlManager.getPreparedStatement(conn, "C_STATICEXPORT_DELETE_ALL_PUBLISHED_LINKS"); 251 stmt.setInt(1, linkType); 252 stmt.executeUpdate(); 253 } catch (SQLException e) { 254 throw new CmsDbSqlException(Messages.get().container( 255 Messages.ERR_GENERIC_SQL_1, 256 CmsDbSqlException.getErrorQuery(stmt)), e); 257 } finally { 258 m_sqlManager.closeAll(dbc, conn, stmt, null); 259 } 260 } 261 262 265 public void deleteProject(CmsDbContext dbc, CmsProject project) throws CmsDataAccessException { 266 267 deleteProjectResources(dbc, project); 269 270 unmarkProjectResources(dbc, project); 272 273 Connection conn = null; 275 PreparedStatement stmt = null; 276 try { 277 conn = m_sqlManager.getConnection(dbc, project.getId()); 278 stmt = m_sqlManager.getPreparedStatement(conn, "C_PROJECTS_DELETE"); 279 stmt.setInt(1, project.getId()); 281 stmt.executeUpdate(); 282 } catch (SQLException e) { 283 throw new CmsDbSqlException(Messages.get().container( 284 Messages.ERR_GENERIC_SQL_1, 285 CmsDbSqlException.getErrorQuery(stmt)), e); 286 } finally { 287 m_sqlManager.closeAll(dbc, conn, stmt, null); 288 } 289 } 290 291 294 public void deleteProjectResource(CmsDbContext dbc, int projectId, String resourceName) 295 throws CmsDataAccessException { 296 297 Connection conn = null; 298 PreparedStatement stmt = null; 299 try { 300 conn = m_sqlManager.getConnection(dbc); 301 stmt = m_sqlManager.getPreparedStatement(conn, "C_PROJECTRESOURCES_DELETE"); 302 stmt.setInt(1, projectId); 304 stmt.setString(2, resourceName); 305 stmt.executeUpdate(); 306 } catch (SQLException e) { 307 throw new CmsDbSqlException(Messages.get().container( 308 Messages.ERR_GENERIC_SQL_1, 309 CmsDbSqlException.getErrorQuery(stmt)), e); 310 } finally { 311 m_sqlManager.closeAll(dbc, conn, stmt, null); 312 } 313 } 314 315 318 public void deleteProjectResources(CmsDbContext dbc, CmsProject project) throws CmsDataAccessException { 319 320 Connection conn = null; 321 PreparedStatement stmt = null; 322 323 try { 324 conn = m_sqlManager.getConnection(dbc, project.getId()); 325 stmt = m_sqlManager.getPreparedStatement(conn, "C_PROJECTRESOURCES_DELETEALL"); 326 stmt.setInt(1, project.getId()); 327 stmt.executeUpdate(); 328 } catch (SQLException e) { 329 throw new CmsDbSqlException(Messages.get().container( 330 Messages.ERR_GENERIC_SQL_1, 331 CmsDbSqlException.getErrorQuery(stmt)), e); 332 } finally { 333 m_sqlManager.closeAll(dbc, conn, stmt, null); 334 } 335 } 336 337 340 public void deletePublishHistory(CmsDbContext dbc, int projectId, int maxBackupTagId) throws CmsDataAccessException { 341 342 PreparedStatement stmt = null; 343 Connection conn = null; 344 345 try { 346 conn = m_sqlManager.getConnection(dbc, projectId); 347 stmt = m_sqlManager.getPreparedStatement(conn, projectId, "C_DELETE_PUBLISH_HISTORY"); 348 stmt.setInt(1, maxBackupTagId); 349 stmt.executeUpdate(); 350 } catch (SQLException e) { 351 throw new CmsDbSqlException(Messages.get().container( 352 Messages.ERR_GENERIC_SQL_1, 353 CmsDbSqlException.getErrorQuery(stmt)), e); 354 } finally { 355 m_sqlManager.closeAll(dbc, conn, stmt, null); 356 } 357 } 358 359 362 public void deletePublishHistoryEntry( 363 CmsDbContext dbc, 364 int projectId, 365 CmsUUID publishHistoryId, 366 CmsPublishedResource publishedResource) throws CmsDataAccessException { 367 368 Connection conn = null; 369 PreparedStatement stmt = null; 370 371 try { 372 conn = m_sqlManager.getConnection(dbc, projectId); 373 stmt = m_sqlManager.getPreparedStatement(conn, "C_RESOURCES_DELETE_PUBLISH_HISTORY_ENTRY"); 374 stmt.setString(1, publishHistoryId.toString()); 375 stmt.setInt(2, publishedResource.getBackupTagId()); 376 stmt.setString(3, publishedResource.getStructureId().toString()); 377 stmt.setString(4, publishedResource.getResourceId().toString()); 378 stmt.executeUpdate(); 379 } catch (SQLException e) { 380 throw new CmsDbSqlException(Messages.get().container( 381 Messages.ERR_GENERIC_SQL_1, 382 CmsDbSqlException.getErrorQuery(stmt)), e); 383 } finally { 384 m_sqlManager.closeAll(dbc, conn, stmt, null); 385 } 386 } 387 388 391 public void deleteStaticExportPublishedResource( 392 CmsDbContext dbc, 393 CmsProject currentProject, 394 String resourceName, 395 int linkType, 396 String linkParameter) throws CmsDataAccessException { 397 398 Connection conn = null; 399 PreparedStatement stmt = null; 400 401 try { 402 conn = m_sqlManager.getConnection(dbc, currentProject.getId()); 403 stmt = m_sqlManager.getPreparedStatement(conn, "C_STATICEXPORT_DELETE_PUBLISHED_LINKS"); 404 stmt.setString(1, resourceName); 405 stmt.setInt(2, linkType); 406 stmt.setString(3, linkParameter); 407 stmt.executeUpdate(); 408 } catch (SQLException e) { 409 throw new CmsDbSqlException(Messages.get().container( 410 Messages.ERR_GENERIC_SQL_1, 411 CmsDbSqlException.getErrorQuery(stmt)), e); 412 } finally { 413 m_sqlManager.closeAll(dbc, conn, stmt, null); 414 } 415 } 416 417 420 public void destroy() throws Throwable { 421 422 finalize(); 423 if (CmsLog.INIT.isInfoEnabled()) { 424 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SHUTDOWN_DRIVER_1, getClass().getName())); 425 } 426 } 427 428 431 public void fillDefaults(CmsDbContext dbc) throws CmsDataAccessException { 432 433 try { 434 if (readProject(dbc, CmsProject.ONLINE_PROJECT_ID) != null) { 435 return; 437 } 438 } catch (CmsDataAccessException exc) { 439 } 441 442 if (CmsLog.INIT.isInfoEnabled()) { 443 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_FILL_DEFAULTS_0)); 444 } 445 446 String adminUser = OpenCms.getDefaultUsers().getUserAdmin(); 447 CmsUser admin = m_driverManager.readUser(dbc, adminUser); 448 449 String administratorsGroup = OpenCms.getDefaultUsers().getGroupAdministrators(); 450 CmsGroup administrators = m_driverManager.readGroup(dbc, administratorsGroup); 451 452 String usersGroup = OpenCms.getDefaultUsers().getGroupUsers(); 453 CmsGroup users = m_driverManager.readGroup(dbc, usersGroup); 454 455 String projectmanagersGroup = OpenCms.getDefaultUsers().getGroupProjectmanagers(); 456 CmsGroup projectmanager = m_driverManager.readGroup(dbc, projectmanagersGroup); 457 458 m_driverManager.getWorkflowDriver().writeTaskType(dbc, 1, 0, "../taskforms/adhoc.asp", "Ad-Hoc", "30308", 1, 1); 459 460 464 CmsTask task = m_driverManager.getWorkflowDriver().createTask( 466 dbc, 467 0, 468 0, 469 1, 470 admin.getId(), 471 admin.getId(), 472 administrators.getId(), 473 CmsProject.ONLINE_PROJECT_NAME, 474 new java.sql.Timestamp (new java.util.Date ().getTime()), 475 new java.sql.Timestamp (new java.util.Date ().getTime()), 476 CmsTaskService.TASK_PRIORITY_NORMAL); 477 CmsProject onlineProject = createProject( 478 dbc, 479 admin, 480 users, 481 projectmanager, 482 task, 483 CmsProject.ONLINE_PROJECT_NAME, 484 "The Online Project", 485 I_CmsPrincipal.FLAG_ENABLED, 486 CmsProject.PROJECT_TYPE_NORMAL, 487 null); 488 489 CmsFolder onlineRootFolder = new CmsFolder( 491 new CmsUUID(), 492 new CmsUUID(), 493 "/", 494 CmsResourceTypeFolder.RESOURCE_TYPE_ID, 495 0, 496 onlineProject.getId(), 497 CmsResource.STATE_NEW, 498 0, 499 admin.getId(), 500 0, 501 admin.getId(), 502 1, 503 CmsResource.DATE_RELEASED_DEFAULT, 504 CmsResource.DATE_EXPIRED_DEFAULT); 505 506 m_driverManager.getVfsDriver().createResource(dbc, onlineProject, onlineRootFolder, null); 507 508 onlineRootFolder.setState(CmsResource.STATE_UNCHANGED); 509 510 m_driverManager.getVfsDriver().writeResource(dbc, onlineProject, onlineRootFolder, CmsDriverManager.UPDATE_ALL); 511 512 m_driverManager.getProjectDriver().createProjectResource( 514 dbc, 515 onlineProject.getId(), 516 onlineRootFolder.getRootPath(), 517 null); 518 519 523 task = m_driverManager.getWorkflowDriver().createTask( 525 dbc, 526 0, 527 0, 528 1, 529 admin.getId(), 530 admin.getId(), 531 administrators.getId(), 532 "_setupProject", 533 new java.sql.Timestamp (new java.util.Date ().getTime()), 534 new java.sql.Timestamp (new java.util.Date ().getTime()), 535 CmsTaskService.TASK_PRIORITY_NORMAL); 536 537 CmsProject setupProject = m_driverManager.getProjectDriver().createProject( 539 dbc, 540 admin, 541 administrators, 542 administrators, 543 task, 544 "_setupProject", 545 "Initial site import", 546 I_CmsPrincipal.FLAG_ENABLED, 547 CmsProject.PROJECT_TYPE_TEMPORARY, 548 null); 549 550 CmsResource offlineRootFolder = m_driverManager.getVfsDriver().createResource( 552 dbc, 553 setupProject, 554 onlineRootFolder, 555 null); 556 557 offlineRootFolder.setState(CmsResource.STATE_UNCHANGED); 558 559 m_driverManager.getVfsDriver().writeResource(dbc, setupProject, offlineRootFolder, CmsDriverManager.UPDATE_ALL); 560 561 m_driverManager.getProjectDriver().createProjectResource( 563 dbc, 564 setupProject.getId(), 565 offlineRootFolder.getRootPath(), 566 null); 567 } 568 569 572 public CmsSqlManager getSqlManager() { 573 574 return m_sqlManager; 575 } 576 577 580 public void init( 581 CmsDbContext dbc, 582 CmsConfigurationManager configurationManager, 583 List successiveDrivers, 584 CmsDriverManager driverManager) { 585 586 Map configuration = configurationManager.getConfiguration(); 587 String poolUrl = configuration.get("db.project.pool").toString(); 588 String classname = configuration.get("db.project.sqlmanager").toString(); 589 m_sqlManager = this.initSqlManager(classname); 590 m_sqlManager.init(I_CmsProjectDriver.DRIVER_TYPE_ID, poolUrl); 591 592 m_driverManager = driverManager; 593 594 if (CmsLog.INIT.isInfoEnabled()) { 595 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_ASSIGNED_POOL_1, poolUrl)); 596 } 597 598 if (successiveDrivers != null && !successiveDrivers.isEmpty()) { 599 if (LOG.isWarnEnabled()) { 600 LOG.warn(Messages.get().getBundle().key( 601 Messages.LOG_SUCCESSIVE_DRIVERS_UNSUPPORTED_1, 602 getClass().getName())); 603 } 604 } 605 } 606 607 610 public org.opencms.db.generic.CmsSqlManager initSqlManager(String classname) { 611 612 return CmsSqlManager.getInstance(classname); 613 } 614 615 618 public void publishDeletedFolder( 619 CmsDbContext dbc, 620 I_CmsReport report, 621 int m, 622 int n, 623 CmsProject onlineProject, 624 CmsFolder currentFolder, 625 boolean backupEnabled, 626 long publishDate, 627 CmsUUID publishHistoryId, 628 int backupTagId, 629 int maxVersions) throws CmsDataAccessException { 630 631 CmsFolder onlineFolder = null; 632 List offlineProperties = null; 633 634 try { 635 report.print(org.opencms.report.Messages.get().container( 636 org.opencms.report.Messages.RPT_SUCCESSION_2, 637 String.valueOf(m), 638 String.valueOf(n)), I_CmsReport.FORMAT_NOTE); 639 report.print(Messages.get().container(Messages.RPT_DELETE_FOLDER_0), I_CmsReport.FORMAT_NOTE); 640 report.print(org.opencms.report.Messages.get().container( 641 org.opencms.report.Messages.RPT_ARGUMENT_1, 642 dbc.removeSiteRoot(currentFolder.getRootPath()))); 643 report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0)); 644 645 try { 646 if (backupEnabled) { 648 offlineProperties = m_driverManager.getVfsDriver().readPropertyObjects( 649 dbc, 650 dbc.currentProject(), 651 currentFolder); 652 m_driverManager.getBackupDriver().writeBackupResource( 653 dbc, 654 currentFolder, 655 offlineProperties, 656 backupTagId, 657 publishDate, 658 maxVersions); 659 } 660 661 m_driverManager.getProjectDriver().writePublishHistory( 662 dbc, 663 dbc.currentProject(), 664 publishHistoryId, 665 new CmsPublishedResource(currentFolder, backupTagId)); 666 } catch (CmsDataAccessException e) { 667 if (LOG.isErrorEnabled()) { 668 LOG.error(Messages.get().getBundle().key( 669 Messages.LOG_WRITING_PUBLISHING_HISTORY_1, 670 currentFolder.getRootPath()), e); 671 } 672 throw e; 673 } 674 675 onlineFolder = m_driverManager.readFolder(dbc, currentFolder.getRootPath(), CmsResourceFilter.ALL); 677 678 try { 679 m_driverManager.getVfsDriver().deletePropertyObjects( 681 dbc, 682 onlineProject.getId(), 683 onlineFolder, 684 CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_AND_RESOURCE_VALUES); 685 m_driverManager.getVfsDriver().deletePropertyObjects( 686 dbc, 687 dbc.currentProject().getId(), 688 currentFolder, 689 CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_AND_RESOURCE_VALUES); 690 } catch (CmsDataAccessException e) { 691 if (LOG.isErrorEnabled()) { 692 LOG.error(Messages.get().getBundle().key( 693 Messages.LOG_DELETING_PROPERTIES_1, 694 currentFolder.getRootPath()), e); 695 } 696 throw e; 697 } 698 699 try { 700 m_driverManager.getVfsDriver().removeFolder(dbc, dbc.currentProject(), currentFolder); 702 703 try { 704 m_driverManager.getVfsDriver().readFolder( 705 dbc, 706 dbc.currentProject().getId(), 707 currentFolder.getRootPath()); 708 } catch (CmsVfsResourceNotFoundException e) { 709 m_driverManager.getVfsDriver().removeFolder(dbc, onlineProject, currentFolder); 711 } 712 } catch (CmsDataAccessException e) { 713 if (LOG.isErrorEnabled()) { 714 LOG.error(Messages.get().getBundle().key( 715 Messages.LOG_REMOVING_RESOURCE_1, 716 currentFolder.getRootPath()), e); 717 } 718 throw e; 719 } 720 721 try { 722 m_driverManager.getUserDriver().removeAccessControlEntries( 724 dbc, 725 onlineProject, 726 onlineFolder.getResourceId()); 727 m_driverManager.getUserDriver().removeAccessControlEntries( 728 dbc, 729 dbc.currentProject(), 730 currentFolder.getResourceId()); 731 } catch (CmsDataAccessException e) { 732 if (LOG.isErrorEnabled()) { 733 LOG.error( 734 Messages.get().getBundle().key(Messages.LOG_REMOVING_ACL_1, currentFolder.getRootPath()), 735 e); 736 } 737 throw e; 738 } 739 740 report.println( 741 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0), 742 I_CmsReport.FORMAT_OK); 743 744 if (LOG.isDebugEnabled()) { 745 if (LOG.isDebugEnabled()) { 746 LOG.debug(Messages.get().getBundle().key( 747 Messages.LOG_DEL_FOLDER_3, 748 currentFolder.getRootPath(), 749 String.valueOf(m), 750 String.valueOf(n))); 751 } 752 } 753 } finally { 754 OpenCms.fireCmsEvent(new CmsEvent( 756 I_CmsEventListener.EVENT_RESOURCE_AND_PROPERTIES_MODIFIED, 757 Collections.singletonMap("resource", currentFolder))); 758 } 759 } 760 761 764 public void publishFile( 765 CmsDbContext dbc, 766 I_CmsReport report, 767 int m, 768 int n, 769 CmsProject onlineProject, 770 CmsResource offlineResource, 771 Set publishedContentIds, 772 boolean backupEnabled, 773 long publishDate, 774 CmsUUID publishHistoryId, 775 int backupTagId, 776 int maxVersions) throws CmsDataAccessException { 777 778 CmsFile newFile = null; 779 CmsResource onlineResource = null; 780 List offlineProperties = null; 781 CmsProperty property = null; 782 int propertyDeleteOption = -1; 783 784 793 794 try { 795 if (offlineResource.getState() == CmsResource.STATE_DELETED) { 796 report.print(org.opencms.report.Messages.get().container( 797 org.opencms.report.Messages.RPT_SUCCESSION_2, 798 String.valueOf(m), 799 String.valueOf(n)), I_CmsReport.FORMAT_NOTE); 800 report.print(Messages.get().container(Messages.RPT_DELETE_FILE_0), I_CmsReport.FORMAT_NOTE); 801 report.print(org.opencms.report.Messages.get().container( 802 org.opencms.report.Messages.RPT_ARGUMENT_1, 803 dbc.removeSiteRoot(offlineResource.getRootPath()))); 804 report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0)); 805 806 try { 807 onlineResource = m_driverManager.getVfsDriver().readResource( 809 dbc, 810 onlineProject.getId(), 811 offlineResource.getStructureId(), 812 true); 813 } catch (CmsDataAccessException e) { 814 if (LOG.isErrorEnabled()) { 815 LOG.error(Messages.get().getBundle().key( 816 Messages.LOG_READING_RESOURCE_1, 817 offlineResource.getRootPath()), e); 818 } 819 throw e; 820 } 821 822 if (offlineResource.isLabeled() && !m_driverManager.labelResource(dbc, offlineResource, null, 2)) { 823 int flags = offlineResource.getFlags(); 825 flags &= ~CmsResource.FLAG_LABELED; 826 offlineResource.setFlags(flags); 827 } 828 829 try { 830 if (backupEnabled && !OpenCms.getSystemInfo().keepVersionHistory()) { 832 m_driverManager.deleteBackup(dbc, offlineResource); 834 } 835 m_driverManager.getProjectDriver().writePublishHistory( 836 dbc, 837 dbc.currentProject(), 838 publishHistoryId, 839 new CmsPublishedResource(offlineResource, backupTagId)); 840 } catch (CmsDataAccessException e) { 841 if (LOG.isErrorEnabled()) { 842 LOG.error(Messages.get().getBundle().key( 843 Messages.LOG_WRITING_PUBLISHING_HISTORY_1, 844 offlineResource.getRootPath()), e); 845 } 846 throw e; 847 } 848 849 try { 850 if (offlineResource.getSiblingCount() > 1) { 852 propertyDeleteOption = CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_VALUES; 854 } else { 855 propertyDeleteOption = CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_AND_RESOURCE_VALUES; 857 } 858 859 m_driverManager.getVfsDriver().deletePropertyObjects( 860 dbc, 861 onlineProject.getId(), 862 onlineResource, 863 propertyDeleteOption); 864 m_driverManager.getVfsDriver().deletePropertyObjects( 865 dbc, 866 dbc.currentProject().getId(), 867 offlineResource, 868 propertyDeleteOption); 869 870 if (!onlineResource.getResourceId().equals(offlineResource.getResourceId())) { 875 m_driverManager.getVfsDriver().deletePropertyObjects( 876 dbc, 877 dbc.currentProject().getId(), 878 onlineResource, 879 CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_AND_RESOURCE_VALUES); 880 } 881 } catch (CmsDataAccessException e) { 882 if (LOG.isErrorEnabled()) { 883 LOG.error(Messages.get().getBundle().key( 884 Messages.LOG_DELETING_PROPERTIES_1, 885 offlineResource.getRootPath()), e); 886 } 887 throw e; 888 } 889 890 try { 891 m_driverManager.getVfsDriver().removeFile(dbc, dbc.currentProject(), offlineResource, true); 893 894 try { 895 m_driverManager.getVfsDriver().readResource( 896 dbc, 897 dbc.currentProject().getId(), 898 offlineResource.getStructureId(), 899 true); 900 } catch (CmsVfsResourceNotFoundException e) { 901 m_driverManager.getVfsDriver().removeFile(dbc, onlineProject, onlineResource, true); 903 } 904 } catch (CmsDataAccessException e) { 905 if (LOG.isErrorEnabled()) { 906 LOG.error(Messages.get().getBundle().key( 907 Messages.LOG_REMOVING_RESOURCE_1, 908 offlineResource.getRootPath()), e); 909 } 910 throw e; 911 } 912 913 try { 914 m_driverManager.getUserDriver().removeAccessControlEntries( 916 dbc, 917 onlineProject, 918 onlineResource.getResourceId()); 919 m_driverManager.getUserDriver().removeAccessControlEntries( 920 dbc, 921 dbc.currentProject(), 922 offlineResource.getResourceId()); 923 } catch (CmsDataAccessException e) { 924 if (LOG.isErrorEnabled()) { 925 LOG.error(Messages.get().getBundle().key( 926 Messages.LOG_REMOVING_ACL_1, 927 offlineResource.toString()), e); 928 } 929 throw e; 930 } 931 report.println( 932 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0), 933 I_CmsReport.FORMAT_OK); 934 935 if (LOG.isDebugEnabled()) { 936 LOG.debug(Messages.get().getBundle().key( 937 Messages.LOG_DEL_FILE_3, 938 offlineResource.getRootPath(), 939 String.valueOf(m), 940 String.valueOf(n))); 941 } 942 943 } else if (offlineResource.getState() == CmsResource.STATE_CHANGED) { 944 report.print(org.opencms.report.Messages.get().container( 945 org.opencms.report.Messages.RPT_SUCCESSION_2, 946 String.valueOf(m), 947 String.valueOf(n)), I_CmsReport.FORMAT_NOTE); 948 report.print(Messages.get().container(Messages.RPT_PUBLISH_FILE_0), I_CmsReport.FORMAT_NOTE); 949 report.print(org.opencms.report.Messages.get().container( 950 org.opencms.report.Messages.RPT_ARGUMENT_1, 951 dbc.removeSiteRoot(offlineResource.getRootPath()))); 952 report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0)); 953 954 try { 955 onlineResource = m_driverManager.getVfsDriver().readResource( 957 dbc, 958 onlineProject.getId(), 959 offlineResource.getStructureId(), 960 false); 961 962 int flags = offlineResource.getFlags(); 964 flags &= ~CmsResource.FLAG_LABELED; 965 offlineResource.setFlags(flags); 966 967 m_driverManager.getVfsDriver().deletePropertyObjects( 969 dbc, 970 onlineProject.getId(), 971 onlineResource, 972 CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_AND_RESOURCE_VALUES); 973 974 981 if (!onlineResource.getResourceId().equals(offlineResource.getResourceId())) { 982 offlineProperties = m_driverManager.getVfsDriver().readPropertyObjects( 983 dbc, 984 dbc.currentProject(), 985 onlineResource); 986 if (offlineProperties.size() > 0) { 987 for (int i = 0; i < offlineProperties.size(); i++) { 988 property = (CmsProperty)offlineProperties.get(i); 989 property.setStructureValue(null); 990 property.setResourceValue(CmsProperty.DELETE_VALUE); 991 } 992 m_driverManager.getVfsDriver().writePropertyObjects( 993 dbc, 994 dbc.currentProject(), 995 onlineResource, 996 offlineProperties); 997 } 998 } 999 1000 boolean removeContent = !publishedContentIds.contains(offlineResource.getResourceId()); 1002 m_driverManager.getVfsDriver().removeFile(dbc, onlineProject, onlineResource, removeContent); 1003 } catch (CmsDataAccessException e) { 1004 if (LOG.isErrorEnabled()) { 1005 LOG.error(Messages.get().getBundle().key( 1006 Messages.LOG_DELETING_PROPERTIES_1, 1007 offlineResource.toString()), e); 1008 } 1009 1010 throw e; 1011 } 1012 1013 try { 1014 newFile = m_driverManager.getProjectDriver().publishFileContent( 1016 dbc, 1017 dbc.currentProject(), 1018 onlineProject, 1019 offlineResource, 1020 publishedContentIds); 1021 } catch (CmsDataAccessException e) { 1022 if (LOG.isErrorEnabled()) { 1023 LOG.error(Messages.get().getBundle().key( 1024 Messages.LOG_PUBLISHING_RESOURCE_1, 1025 offlineResource.getRootPath()), e); 1026 } 1027 throw e; 1028 } 1029 1030 try { 1031 offlineProperties = m_driverManager.getVfsDriver().readPropertyObjects( 1033 dbc, 1034 dbc.currentProject(), 1035 offlineResource); 1036 CmsProperty.setAutoCreatePropertyDefinitions(offlineProperties, true); 1037 m_driverManager.getVfsDriver().writePropertyObjects(dbc, onlineProject, newFile, offlineProperties); 1038 } catch (CmsDataAccessException e) { 1039 if (LOG.isErrorEnabled()) { 1040 LOG.error(Messages.get().getBundle().key( 1041 Messages.LOG_PUBLISHING_PROPERTIES_1, 1042 newFile.getRootPath()), e); 1043 } 1044 throw e; 1045 } 1046 1047 try { 1048 m_driverManager.getUserDriver().publishAccessControlEntries( 1050 dbc, 1051 dbc.currentProject(), 1052 onlineProject, 1053 newFile.getResourceId(), 1054 onlineResource.getResourceId()); 1055 } catch (CmsDataAccessException e) { 1056 if (LOG.isErrorEnabled()) { 1057 LOG.error( 1058 Messages.get().getBundle().key(Messages.LOG_PUBLISHING_ACL_1, newFile.getRootPath()), 1059 e); 1060 } 1061 throw e; 1062 } 1063 1064 try { 1065 if (backupEnabled) { 1067 if (offlineProperties == null) { 1068 offlineProperties = m_driverManager.getVfsDriver().readPropertyObjects( 1069 dbc, 1070 dbc.currentProject(), 1071 offlineResource); 1072 } 1073 m_driverManager.getBackupDriver().writeBackupResource( 1074 dbc, 1075 newFile, 1076 offlineProperties, 1077 backupTagId, 1078 publishDate, 1079 maxVersions); 1080 } 1081 m_driverManager.getProjectDriver().writePublishHistory( 1082 dbc, 1083 dbc.currentProject(), 1084 publishHistoryId, 1085 new CmsPublishedResource(offlineResource, backupTagId)); 1086 } catch (CmsDataAccessException e) { 1087 if (LOG.isErrorEnabled()) { 1088 LOG.error(Messages.get().getBundle().key( 1089 Messages.LOG_WRITING_PUBLISHING_HISTORY_1, 1090 newFile.getRootPath()), e); 1091 } 1092 throw e; 1093 } 1094 report.println( 1095 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0), 1096 I_CmsReport.FORMAT_OK); 1097 1098 if (LOG.isDebugEnabled()) { 1099 LOG.debug(Messages.get().getBundle().key( 1100 Messages.LOG_PUBLISHING_FILE_3, 1101 offlineResource.getRootPath(), 1102 String.valueOf(m), 1103 String.valueOf(n))); 1104 } 1105 1106 } else if (offlineResource.getState() == CmsResource.STATE_NEW) { 1107 report.print(org.opencms.report.Messages.get().container( 1108 org.opencms.report.Messages.RPT_SUCCESSION_2, 1109 String.valueOf(m), 1110 String.valueOf(n)), I_CmsReport.FORMAT_NOTE); 1111 report.print(Messages.get().container(Messages.RPT_PUBLISH_FILE_0), I_CmsReport.FORMAT_NOTE); 1112 report.print(org.opencms.report.Messages.get().container( 1113 org.opencms.report.Messages.RPT_ARGUMENT_1, 1114 dbc.removeSiteRoot(offlineResource.getRootPath()))); 1115 report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0)); 1116 1117 try { 1118 int flags = offlineResource.getFlags(); 1120 flags &= ~CmsResource.FLAG_LABELED; 1121 offlineResource.setFlags(flags); 1122 1123 newFile = m_driverManager.getProjectDriver().publishFileContent( 1125 dbc, 1126 dbc.currentProject(), 1127 onlineProject, 1128 offlineResource, 1129 publishedContentIds); 1130 } catch (CmsVfsResourceAlreadyExistsException e) { 1131 try { 1132 m_driverManager.getVfsDriver().removeFile(dbc, onlineProject, offlineResource, true); 1135 publishedContentIds.remove(offlineResource.getResourceId()); 1136 newFile = m_driverManager.getProjectDriver().publishFileContent( 1137 dbc, 1138 dbc.currentProject(), 1139 onlineProject, 1140 offlineResource, 1141 publishedContentIds); 1142 } catch (CmsDataAccessException e1) { 1143 if (LOG.isErrorEnabled()) { 1144 LOG.error(Messages.get().getBundle().key( 1145 Messages.LOG_PUBLISHING_RESOURCE_1, 1146 offlineResource.getRootPath()), e); 1147 } 1148 throw e1; 1149 } 1150 } catch (CmsDataAccessException e) { 1151 if (LOG.isErrorEnabled()) { 1152 LOG.error(Messages.get().getBundle().key( 1153 Messages.LOG_PUBLISHING_RESOURCE_1, 1154 offlineResource.getRootPath()), e); 1155 } 1156 throw e; 1157 } 1158 1159 try { 1160 offlineProperties = m_driverManager.getVfsDriver().readPropertyObjects( 1162 dbc, 1163 dbc.currentProject(), 1164 offlineResource); 1165 CmsProperty.setAutoCreatePropertyDefinitions(offlineProperties, true); 1166 m_driverManager.getVfsDriver().writePropertyObjects(dbc, onlineProject, newFile, offlineProperties); 1167 } catch (CmsDataAccessException e) { 1168 if (LOG.isErrorEnabled()) { 1169 LOG.error(Messages.get().getBundle().key( 1170 Messages.LOG_PUBLISHING_PROPERTIES_1, 1171 newFile.getRootPath()), e); 1172 } 1173 1174 throw e; 1175 } 1176 1177 try { 1178 m_driverManager.getUserDriver().publishAccessControlEntries( 1180 dbc, 1181 dbc.currentProject(), 1182 onlineProject, 1183 offlineResource.getResourceId(), 1184 newFile.getResourceId()); 1185 } catch (CmsDataAccessException e) { 1186 if (LOG.isErrorEnabled()) { 1187 LOG.error( 1188 Messages.get().getBundle().key(Messages.LOG_PUBLISHING_ACL_1, newFile.getRootPath()), 1189 e); 1190 } 1191 1192 throw e; 1193 } 1194 1195 try { 1196 if (backupEnabled) { 1198 if (offlineProperties == null) { 1199 offlineProperties = m_driverManager.getVfsDriver().readPropertyObjects( 1200 dbc, 1201 dbc.currentProject(), 1202 offlineResource); 1203 } 1204 m_driverManager.getBackupDriver().writeBackupResource( 1205 dbc, 1206 newFile, 1207 offlineProperties, 1208 backupTagId, 1209 publishDate, 1210 maxVersions); 1211 } 1212 1213 m_driverManager.getProjectDriver().writePublishHistory( 1214 dbc, 1215 dbc.currentProject(), 1216 publishHistoryId, 1217 new CmsPublishedResource(offlineResource, backupTagId)); 1218 } catch (CmsDataAccessException e) { 1219 if (LOG.isErrorEnabled()) { 1220 LOG.error(Messages.get().getBundle().key( 1221 Messages.LOG_WRITING_PUBLISHING_HISTORY_1, 1222 newFile.getRootPath()), e); 1223 } 1224 1225 throw e; 1226 } 1227 report.println( 1228 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0), 1229 I_CmsReport.FORMAT_OK); 1230 1231 if (LOG.isDebugEnabled()) { 1232 if (LOG.isDebugEnabled()) { 1233 LOG.debug(Messages.get().getBundle().key( 1234 Messages.LOG_PUBLISHING_FILE_3, 1235 offlineResource.getRootPath(), 1236 String.valueOf(m), 1237 String.valueOf(n))); 1238 } 1239 } 1240 } 1241 } finally { 1242 OpenCms.fireCmsEvent(new CmsEvent( 1244 I_CmsEventListener.EVENT_RESOURCE_AND_PROPERTIES_MODIFIED, 1245 Collections.singletonMap("resource", offlineResource))); 1246 } 1247 } 1248 1249 1252 public CmsFile publishFileContent( 1253 CmsDbContext dbc, 1254 CmsProject offlineProject, 1255 CmsProject onlineProject, 1256 CmsResource offlineResource, 1257 Set publishedResourceIds) throws CmsDataAccessException { 1258 1259 CmsFile newFile = null; 1260 CmsFile offlineFile = null; 1261 1262 try { 1263 if (!publishedResourceIds.contains(offlineResource.getResourceId())) { 1265 offlineFile = m_driverManager.getVfsDriver().readFile( 1267 dbc, 1268 offlineProject.getId(), 1269 false, 1270 offlineResource.getStructureId()); 1271 1272 newFile = (CmsFile)offlineFile.clone(); 1274 newFile.setState(CmsResource.STATE_UNCHANGED); 1275 1276 m_driverManager.getVfsDriver().createResource(dbc, onlineProject, newFile, newFile.getContents()); 1277 1278 m_driverManager.getVfsDriver().publishResource(dbc, onlineProject, newFile, offlineFile, false); 1280 1281 publishedResourceIds.add(offlineFile.getResourceId()); 1284 1285 } else { 1286 m_driverManager.getVfsDriver().createSibling(dbc, onlineProject, offlineResource); 1288 1289 newFile = m_driverManager.getVfsDriver().readFile( 1290 dbc, 1291 onlineProject.getId(), 1292 false, 1293 offlineResource.getStructureId()); 1294 } 1295 } catch (CmsDataAccessException e) { 1296 if (LOG.isErrorEnabled()) { 1297 LOG.error(Messages.get().getBundle().key( 1298 Messages.LOG_PUBLISHING_FILE_CONTENT_1, 1299 offlineResource.toString()), e); 1300 } 1301 1302 throw e; 1303 } 1304 1305 return newFile; 1306 } 1307 1308 1311 public void publishFolder( 1312 CmsDbContext dbc, 1313 I_CmsReport report, 1314 int m, 1315 int n, 1316 CmsProject onlineProject, 1317 CmsFolder offlineFolder, 1318 boolean backupEnabled, 1319 long publishDate, 1320 CmsUUID publishHistoryId, 1321 int backupTagId, 1322 int maxVersions) throws CmsDataAccessException { 1323 1324 CmsResource newFolder = null; 1325 CmsResource onlineFolder = null; 1326 List offlineProperties = null; 1327 1328 try { 1329 report.print(org.opencms.report.Messages.get().container( 1330 org.opencms.report.Messages.RPT_SUCCESSION_2, 1331 String.valueOf(m), 1332 String.valueOf(n)), I_CmsReport.FORMAT_NOTE); 1333 report.print(Messages.get().container(Messages.RPT_PUBLISH_FOLDER_0), I_CmsReport.FORMAT_NOTE); 1334 report.print(org.opencms.report.Messages.get().container( 1335 org.opencms.report.Messages.RPT_ARGUMENT_1, 1336 dbc.removeSiteRoot(offlineFolder.getRootPath()))); 1337 report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0)); 1338 1339 if (offlineFolder.getState() == CmsResource.STATE_NEW) { 1340 1341 try { 1342 newFolder = (CmsFolder)offlineFolder.clone(); 1344 newFolder.setState(CmsResource.STATE_UNCHANGED); 1345 1346 onlineFolder = m_driverManager.getVfsDriver().createResource(dbc, onlineProject, newFolder, null); 1347 } catch (CmsVfsResourceAlreadyExistsException e) { 1348 try { 1349 onlineFolder = m_driverManager.getVfsDriver().readFolder( 1350 dbc, 1351 onlineProject.getId(), 1352 newFolder.getRootPath()); 1353 m_driverManager.getVfsDriver().publishResource( 1354 dbc, 1355 onlineProject, 1356 onlineFolder, 1357 offlineFolder, 1358 false); 1359 } catch (CmsDataAccessException e1) { 1360 if (LOG.isErrorEnabled()) { 1361 LOG.error(Messages.get().getBundle().key( 1362 Messages.LOG_READING_RESOURCE_1, 1363 offlineFolder.getRootPath()), e); 1364 } 1365 throw e1; 1366 } 1367 } catch (CmsDataAccessException e) { 1368 if (LOG.isErrorEnabled()) { 1369 LOG.error(Messages.get().getBundle().key( 1370 Messages.LOG_PUBLISHING_RESOURCE_1, 1371 offlineFolder.getRootPath()), e); 1372 } 1373 throw e; 1374 } 1375 1376 } else if (offlineFolder.getState() == CmsResource.STATE_CHANGED) { 1377 1378 try { 1379 onlineFolder = m_driverManager.getVfsDriver().readFolder( 1381 dbc, 1382 onlineProject.getId(), 1383 offlineFolder.getStructureId()); 1384 } catch (CmsVfsResourceNotFoundException e) { 1385 try { 1386 onlineFolder = m_driverManager.getVfsDriver().createResource( 1387 dbc, 1388 onlineProject, 1389 offlineFolder, 1390 null); 1391 onlineFolder.setState(CmsResource.STATE_UNCHANGED); 1392 m_driverManager.getVfsDriver().writeResourceState( 1393 dbc, 1394 dbc.currentProject(), 1395 onlineFolder, 1396 CmsDriverManager.UPDATE_ALL); 1397 } catch (CmsDataAccessException e1) { 1398 if (LOG.isErrorEnabled()) { 1399 LOG.error(Messages.get().getBundle().key( 1400 Messages.LOG_PUBLISHING_RESOURCE_1, 1401 offlineFolder.getRootPath()), e); 1402 } 1403 throw e1; 1404 } 1405 } 1406 1407 try { 1408 m_driverManager.getVfsDriver().publishResource( 1410 dbc, 1411 onlineProject, 1412 onlineFolder, 1413 offlineFolder, 1414 false); 1415 } catch (CmsDataAccessException e) { 1416 if (LOG.isErrorEnabled()) { 1417 LOG.error(Messages.get().getBundle().key( 1418 Messages.LOG_PUBLISHING_RESOURCE_1, 1419 offlineFolder.getRootPath()), e); 1420 } 1421 throw e; 1422 } 1423 } 1424 1425 try { 1426 m_driverManager.getUserDriver().publishAccessControlEntries( 1428 dbc, 1429 dbc.currentProject(), 1430 onlineProject, 1431 offlineFolder.getResourceId(), 1432 onlineFolder.getResourceId()); 1433 } catch (CmsDataAccessException e) { 1434 if (LOG.isErrorEnabled()) { 1435 LOG.error( 1436 Messages.get().getBundle().key(Messages.LOG_PUBLISHING_ACL_1, offlineFolder.getRootPath()), 1437 e); 1438 } 1439 throw e; 1440 } 1441 1442 try { 1443 m_driverManager.getVfsDriver().deletePropertyObjects( 1445 dbc, 1446 onlineProject.getId(), 1447 onlineFolder, 1448 CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_AND_RESOURCE_VALUES); 1449 offlineProperties = m_driverManager.getVfsDriver().readPropertyObjects( 1450 dbc, 1451 dbc.currentProject(), 1452 offlineFolder); 1453 CmsProperty.setAutoCreatePropertyDefinitions(offlineProperties, true); 1454 m_driverManager.getVfsDriver().writePropertyObjects(dbc, onlineProject, onlineFolder, offlineProperties); 1455 } catch (CmsDataAccessException e) { 1456 if (LOG.isErrorEnabled()) { 1457 LOG.error(Messages.get().getBundle().key( 1458 Messages.LOG_PUBLISHING_PROPERTIES_1, 1459 offlineFolder.getRootPath()), e); 1460 } 1461 throw e; 1462 } 1463 1464 try { 1465 if (backupEnabled) { 1467 if (offlineProperties == null) { 1468 offlineProperties = m_driverManager.getVfsDriver().readPropertyObjects( 1469 dbc, 1470 dbc.currentProject(), 1471 offlineFolder); 1472 } 1473 1474 m_driverManager.getBackupDriver().writeBackupResource( 1475 dbc, 1476 offlineFolder, 1477 offlineProperties, 1478 backupTagId, 1479 publishDate, 1480 maxVersions); 1481 } 1482 1483 m_driverManager.getProjectDriver().writePublishHistory( 1484 dbc, 1485 dbc.currentProject(), 1486 publishHistoryId, 1487 new CmsPublishedResource(offlineFolder, backupTagId)); 1488 } catch (CmsDataAccessException e) { 1489 if (LOG.isErrorEnabled()) { 1490 LOG.error(Messages.get().getBundle().key( 1491 Messages.LOG_WRITING_PUBLISHING_HISTORY_1, 1492 offlineFolder.getRootPath()), e); 1493 } 1494 throw e; 1495 } 1496 report.println( 1497 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0), 1498 I_CmsReport.FORMAT_OK); 1499 1500 if (LOG.isDebugEnabled()) { 1501 LOG.debug(Messages.get().getBundle().key( 1502 Messages.LOG_PUBLISHING_FOLDER_3, 1503 offlineFolder.getRootPath(), 1504 String.valueOf(m), 1505 String.valueOf(n))); 1506 } 1507 } finally { 1508 OpenCms.fireCmsEvent(new CmsEvent( 1510 I_CmsEventListener.EVENT_RESOURCE_AND_PROPERTIES_MODIFIED, 1511 Collections.singletonMap("resource", offlineFolder))); 1512 } 1513 } 1514 1515 1518 public void publishProject( 1519 CmsDbContext dbc, 1520 I_CmsReport report, 1521 CmsProject onlineProject, 1522 CmsPublishList publishList, 1523 boolean backupEnabled, 1524 int backupTagId, 1525 int maxVersions) throws CmsException { 1526 1527 CmsResource currentResource = null; 1528 long publishDate = System.currentTimeMillis(); 1529 Iterator i = null; 1530 int n; 1531 int publishedFolderCount = 0; 1532 int deletedFolderCount = 0; 1533 int publishedFileCount = 0; 1534 Set publishedContentIds = new HashSet (); 1535 1536 try { 1537 1538 1540 1542 if (backupEnabled) { 1543 1544 try { 1545 m_driverManager.getBackupDriver().writeBackupProject(dbc, backupTagId, publishDate); 1547 dbc.pop(); 1548 } catch (Throwable t) { 1549 dbc.report(report, Messages.get().container( 1550 Messages.ERR_WRITING_BACKUP_OF_PROJECT_1, 1551 dbc.currentProject().getName()), t); 1552 } 1553 } 1554 1555 1557 1559 if (LOG.isDebugEnabled()) { 1560 LOG.debug(Messages.get().getBundle().key( 1561 Messages.LOG_START_PUBLISHING_PROJECT_2, 1562 dbc.currentProject().getName(), 1563 dbc.currentUser().getName())); 1564 } 1565 1566 publishedFolderCount = 0; 1567 n = publishList.getFolderList().size(); 1568 i = publishList.getFolderList().iterator(); 1569 1570 if (n > 0) { 1571 report.println( 1572 Messages.get().container(Messages.RPT_PUBLISH_FOLDERS_BEGIN_0), 1573 I_CmsReport.FORMAT_HEADLINE); 1574 } 1575 1576 while (i.hasNext()) { 1577 CmsResource currentFolder = (CmsResource)i.next(); 1578 1579 try { 1580 if (currentFolder.getState() == CmsResource.STATE_NEW) { 1581 1582 m_driverManager.getProjectDriver().publishFolder( 1584 dbc, 1585 report, 1586 ++publishedFolderCount, 1587 n, 1588 onlineProject, 1589 new CmsFolder(currentFolder), 1590 backupEnabled, 1591 publishDate, 1592 publishList.getPublishHistoryId(), 1593 backupTagId, 1594 maxVersions); 1595 1596 internalResetResourceState(dbc, currentFolder); 1598 1599 } else if (currentFolder.getState() == CmsResource.STATE_CHANGED) { 1600 1601 m_driverManager.getProjectDriver().publishFolder( 1603 dbc, 1604 report, 1605 ++publishedFolderCount, 1606 n, 1607 onlineProject, 1608 new CmsFolder(currentFolder), 1609 backupEnabled, 1610 publishDate, 1611 publishList.getPublishHistoryId(), 1612 backupTagId, 1613 maxVersions); 1614 1615 internalResetResourceState(dbc, currentFolder); 1617 1618 } 1619 1620 dbc.pop(); 1621 } catch (Throwable t) { 1622 dbc.report(report, Messages.get().container( 1623 Messages.ERR_ERROR_PUBLISHING_FOLDER_1, 1624 currentFolder.getRootPath()), t); 1625 } 1626 } 1627 1628 if (n > 0) { 1629 report.println( 1630 Messages.get().container(Messages.RPT_PUBLISH_FOLDERS_END_0), 1631 I_CmsReport.FORMAT_HEADLINE); 1632 } 1633 1634 1636 1638 publishedFileCount = 0; 1639 n = publishList.getFileList().size(); 1640 i = publishList.getFileList().iterator(); 1641 1642 if (n > 0) { 1643 report.println( 1644 Messages.get().container(Messages.RPT_PUBLISH_FILES_BEGIN_0), 1645 I_CmsReport.FORMAT_HEADLINE); 1646 } 1647 1648 while (i.hasNext()) { 1649 1650 currentResource = (CmsResource)i.next(); 1651 1652 try { 1653 m_driverManager.getProjectDriver().publishFile( 1655 dbc, 1656 report, 1657 ++publishedFileCount, 1658 n, 1659 onlineProject, 1660 currentResource, 1661 publishedContentIds, 1662 backupEnabled, 1663 publishDate, 1664 publishList.getPublishHistoryId(), 1665 backupTagId, 1666 maxVersions); 1667 1668 if (currentResource.getState() != CmsResource.STATE_DELETED) { 1669 internalResetResourceState(dbc, currentResource); 1671 } 1672 1673 dbc.pop(); 1674 } catch (Throwable t) { 1675 dbc.report(report, Messages.get().container( 1676 Messages.ERR_ERROR_PUBLISHING_FILE_1, 1677 currentResource.getRootPath()), t); 1678 } 1679 1680 currentResource = null; 1682 } 1683 1684 if (n > 0) { 1685 report.println(Messages.get().container(Messages.RPT_PUBLISH_FILES_END_0), I_CmsReport.FORMAT_HEADLINE); 1686 } 1687 1688 1690 List deletedFolders = publishList.getDeletedFolderList(); 1692 if (deletedFolders.isEmpty()) { 1693 return; 1694 } 1695 1696 deletedFolderCount = 0; 1697 n = deletedFolders.size(); 1698 i = deletedFolders.iterator(); 1699 1700 if (n > 0) { 1701 report.println( 1702 Messages.get().container(Messages.RPT_DELETE_FOLDERS_BEGIN_0), 1703 I_CmsReport.FORMAT_HEADLINE); 1704 } 1705 1706 while (i.hasNext()) { 1707 1708 CmsResource currentFolder = (CmsResource)i.next(); 1709 1710 try { 1711 m_driverManager.getProjectDriver().publishDeletedFolder( 1713 dbc, 1714 report, 1715 ++deletedFolderCount, 1716 n, 1717 onlineProject, 1718 new CmsFolder(currentFolder), 1719 backupEnabled, 1720 publishDate, 1721 publishList.getPublishHistoryId(), 1722 backupTagId, 1723 maxVersions); 1724 1725 dbc.pop(); 1726 } catch (Throwable t) { 1727 dbc.report(report, Messages.get().container( 1728 Messages.ERR_ERROR_PUBLISHING_DELETED_FOLDER_1, 1729 currentFolder.getRootPath()), t); 1730 } 1731 } 1732 1733 if (n > 0) { 1734 report.println(Messages.get().container(Messages.RPT_DELETE_FOLDERS_END_0), I_CmsReport.FORMAT_HEADLINE); 1735 } 1736 } catch (OutOfMemoryError o) { 1737 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_CLEAR_CACHES, Collections.EMPTY_MAP)); 1739 1740 CmsMessageContainer message = Messages.get().container(Messages.ERR_OUT_OF_MEMORY_0); 1741 if (LOG.isErrorEnabled()) { 1742 LOG.error(message.key(), o); 1743 } 1744 throw new CmsDataAccessException(message, o); 1745 1746 } finally { 1747 1748 currentResource = null; 1749 Object [] msgArgs = new Object [] { 1750 String.valueOf(publishedFileCount), 1751 String.valueOf(publishedFolderCount), 1752 String.valueOf(deletedFolderCount), 1753 report.formatRuntime()}; 1754 CmsMessageContainer message = Messages.get().container(Messages.RPT_PUBLISH_STAT_4, msgArgs); 1755 if (LOG.isInfoEnabled()) { 1756 LOG.info(message.key()); 1757 } 1758 report.println(message); 1759 } 1760 } 1761 1762 1765 public CmsProject readProject(CmsDbContext dbc, int id) throws CmsDataAccessException { 1766 1767 PreparedStatement stmt = null; 1768 CmsProject project = null; 1769 ResultSet res = null; 1770 Connection conn = null; 1771 1772 try { 1773 conn = m_sqlManager.getConnection(dbc); 1774 stmt = m_sqlManager.getPreparedStatement(conn, "C_PROJECTS_READ"); 1775 1776 stmt.setInt(1, id); 1777 res = stmt.executeQuery(); 1778 1779 if (res.next()) { 1780 project = new CmsProject( 1781 res.getInt(m_sqlManager.readQuery("C_PROJECTS_PROJECT_ID")), 1782 res.getString(m_sqlManager.readQuery("C_PROJECTS_PROJECT_NAME")), 1783 res.getString(m_sqlManager.readQuery("C_PROJECTS_PROJECT_DESCRIPTION")), 1784 res.getInt(m_sqlManager.readQuery("C_PROJECTS_TASK_ID")), 1785 new CmsUUID(res.getString(m_sqlManager.readQuery("C_PROJECTS_USER_ID"))), 1786 new CmsUUID(res.getString(m_sqlManager.readQuery("C_PROJECTS_GROUP_ID"))), 1787 new CmsUUID(res.getString(m_sqlManager.readQuery("C_PROJECTS_MANAGERGROUP_ID"))), 1788 res.getInt(m_sqlManager.readQuery("C_PROJECTS_PROJECT_FLAGS")), 1789 res.getLong(m_sqlManager.readQuery("C_PROJECTS_DATE_CREATED")), 1790 res.getInt(m_sqlManager.readQuery("C_PROJECTS_PROJECT_TYPE"))); 1791 } else { 1792 throw new CmsDbEntryNotFoundException(Messages.get().container( 1793 Messages.ERR_NO_PROJECT_WITH_ID_1, 1794 String.valueOf(id))); 1795 } 1796 } catch (SQLException e) { 1797 throw new CmsDbSqlException(Messages.get().container( 1798 Messages.ERR_GENERIC_SQL_1, 1799 CmsDbSqlException.getErrorQuery(stmt)), e); 1800 } finally { 1801 m_sqlManager.closeAll(dbc, conn, stmt, res); 1802 } 1803 1804 return project; 1805 } 1806 1807 1810 public CmsProject readProject(CmsDbContext dbc, String name) throws CmsDataAccessException { 1811 1812 PreparedStatement stmt = null; 1813 CmsProject project = null; 1814 ResultSet res = null; 1815 Connection conn = null; 1816 1817 try { 1818 conn = m_sqlManager.getConnection(dbc); 1819 stmt = m_sqlManager.getPreparedStatement(conn, "C_PROJECTS_READ_BYNAME"); 1820 1821 stmt.setString(1, name); 1822 res = stmt.executeQuery(); 1823 1824 if (res.next()) { 1825 project = new CmsProject( 1826 res.getInt(m_sqlManager.readQuery("C_PROJECTS_PROJECT_ID")), 1827 res.getString(m_sqlManager.readQuery("C_PROJECTS_PROJECT_NAME")), 1828 res.getString(m_sqlManager.readQuery("C_PROJECTS_PROJECT_DESCRIPTION")), 1829 res.getInt(m_sqlManager.readQuery("C_PROJECTS_TASK_ID")), 1830 new CmsUUID(res.getString(m_sqlManager.readQuery("C_PROJECTS_USER_ID"))), 1831 new CmsUUID(res.getString(m_sqlManager.readQuery("C_PROJECTS_GROUP_ID"))), 1832 new CmsUUID(res.getString(m_sqlManager.readQuery("C_PROJECTS_MANAGERGROUP_ID"))), 1833 res.getInt(m_sqlManager.readQuery("C_PROJECTS_PROJECT_FLAGS")), 1834 res.getLong(m_sqlManager.readQuery("C_PROJECTS_DATE_CREATED")), 1835 res.getInt(m_sqlManager.readQuery("C_PROJECTS_PROJECT_TYPE"))); 1836 } else { 1837 throw new CmsDbEntryNotFoundException(Messages.get().container( 1838 Messages.ERR_NO_PROJECT_WITH_NAME_1, 1839 name)); 1840 } 1841 } catch (SQLException e) { 1842 throw new CmsDbSqlException(Messages.get().container( 1843 Messages.ERR_GENERIC_SQL_1, 1844 CmsDbSqlException.getErrorQuery(stmt)), e); 1845 } finally { 1846 m_sqlManager.closeAll(dbc, conn, stmt, res); 1847 } 1848 1849 return project; 1850 } 1851 1852 1855 public String readProjectResource(CmsDbContext dbc, int projectId, String resourcePath, Object reservedParam) 1856 throws CmsDataAccessException { 1857 1858 PreparedStatement stmt = null; 1859 Connection conn = null; 1860 ResultSet res = null; 1861 String resName = null; 1862 1863 try { 1864 if (reservedParam == null) { 1865 conn = m_sqlManager.getConnection(dbc); 1867 } else { 1868 conn = m_sqlManager.getConnection(dbc, ((Integer )reservedParam).intValue()); 1870 } 1871 1872 stmt = m_sqlManager.getPreparedStatement(conn, "C_PROJECTRESOURCES_READ"); 1873 1874 stmt.setInt(1, projectId); 1876 stmt.setString(2, resourcePath); 1877 res = stmt.executeQuery(); 1878 1879 if (res.next()) { 1880 resName = res.getString("RESOURCE_PATH"); 1881 } else { 1882 throw new CmsVfsResourceNotFoundException(Messages.get().container( 1883 Messages.ERR_NO_PROJECTRESOURCE_1, 1884 resourcePath)); 1885 } 1886 } catch (SQLException e) { 1887 throw new CmsDbSqlException(Messages.get().container( 1888 Messages.ERR_GENERIC_SQL_1, 1889 CmsDbSqlException.getErrorQuery(stmt)), e); 1890 } finally { 1891 m_sqlManager.closeAll(dbc, conn, stmt, res); 1892 } 1893 return resName; 1894 } 1895 1896 1899 public List readProjectResources(CmsDbContext dbc, CmsProject project) throws CmsDataAccessException { 1900 1901 PreparedStatement stmt = null; 1902 Connection conn = null; 1903 ResultSet res = null; 1904 List result = new ArrayList (); 1905 1906 try { 1907 conn = m_sqlManager.getConnection(dbc); 1908 stmt = m_sqlManager.getPreparedStatement(conn, "C_PROJECTRESOURCES_READ_BY_ID"); 1909 stmt.setInt(1, project.getId()); 1910 res = stmt.executeQuery(); 1911 1912 while (res.next()) { 1913 result.add(res.getString("RESOURCE_PATH")); 1914 } 1915 } catch (SQLException e) { 1916 throw new CmsDbSqlException(Messages.get().container( 1917 Messages.ERR_GENERIC_SQL_1, 1918 CmsDbSqlException.getErrorQuery(stmt)), e); 1919 } finally { 1920 m_sqlManager.closeAll(dbc, conn, stmt, res); 1921 } 1922 1923 return result; 1924 } 1925 1926 1929 public List readProjects(CmsDbContext dbc, int state) throws CmsDataAccessException { 1930 1931 List projects = new ArrayList (); 1932 ResultSet res = null; 1933 PreparedStatement stmt = null; 1934 Connection conn = null; 1935 1936 try { 1937 conn = m_sqlManager.getConnection(dbc); 1939 stmt = m_sqlManager.getPreparedStatement(conn, "C_PROJECTS_READ_BYFLAG"); 1940 1941 stmt.setInt(1, state); 1942 res = stmt.executeQuery(); 1943 1944 while (res.next()) { 1945 projects.add(new CmsProject( 1946 res.getInt(m_sqlManager.readQuery("C_PROJECTS_PROJECT_ID")), 1947 res.getString(m_sqlManager.readQuery("C_PROJECTS_PROJECT_NAME")), 1948 res.getString(m_sqlManager.readQuery("C_PROJECTS_PROJECT_DESCRIPTION")), 1949 res.getInt(m_sqlManager.readQuery("C_PROJECTS_TASK_ID")), 1950 new CmsUUID(res.getString(m_sqlManager.readQuery("C_PROJECTS_USER_ID"))), 1951 new CmsUUID(res.getString(m_sqlManager.readQuery("C_PROJECTS_GROUP_ID"))), 1952 new CmsUUID(res.getString(m_sqlManager.readQuery("C_PROJECTS_MANAGERGROUP_ID"))), 1953 res.getInt(m_sqlManager.readQuery("C_PROJECTS_PROJECT_FLAGS")), 1954 res.getLong(m_sqlManager.readQuery("C_PROJECTS_DATE_CREATED")), 1955 res.getInt(m_sqlManager.readQuery("C_PROJECTS_PROJECT_TYPE")))); 1956 } 1957 } catch (SQLException e) { 1958 throw new CmsDbSqlException(Messages.get().container( 1959 Messages.ERR_GENERIC_SQL_1, 1960 CmsDbSqlException.getErrorQuery(stmt)), e); 1961 } finally { 1962 m_sqlManager.closeAll(dbc, conn, stmt, res); 1963 } 1964 1965 return (projects); 1966 } 1967 1968 1971 public List readProjectsForGroup(CmsDbContext dbc, CmsGroup group) throws CmsDataAccessException { 1972 1973 List projects = new ArrayList (); 1974 ResultSet res = null; 1975 Connection conn = null; 1976 PreparedStatement stmt = null; 1977 1978 try { 1979 conn = m_sqlManager.getConnection(dbc); 1981 stmt = m_sqlManager.getPreparedStatement(conn, "C_PROJECTS_READ_BYGROUP"); 1982 1983 stmt.setString(1, group.getId().toString()); 1984 stmt.setString(2, group.getId().toString()); 1985 res = stmt.executeQuery(); 1986 1987 while (res.next()) { 1988 projects.add(new CmsProject(res, m_sqlManager)); 1989 } 1990 } catch (SQLException e) { 1991 throw new CmsDbSqlException(Messages.get().container( 1992 Messages.ERR_GENERIC_SQL_1, 1993 CmsDbSqlException.getErrorQuery(stmt)), e); 1994 } finally { 1995 m_sqlManager.closeAll(dbc, conn, stmt, res); 1996 } 1997 return (projects); 1998 } 1999 2000 2003 public List readProjectsForManagerGroup(CmsDbContext dbc, CmsGroup group) throws CmsDataAccessException { 2004 2005 List projects = new ArrayList (); 2006 ResultSet res = null; 2007 PreparedStatement stmt = null; 2008 Connection conn = null; 2009 2010 try { 2011 conn = m_sqlManager.getConnection(dbc); 2013 stmt = m_sqlManager.getPreparedStatement(conn, "C_PROJECTS_READ_BYMANAGER"); 2014 2015 stmt.setString(1, group.getId().toString()); 2016 res = stmt.executeQuery(); 2017 2018 while (res.next()) { 2019 projects.add(new CmsProject(res, m_sqlManager)); 2020 } 2021 } catch (SQLException e) { 2022 throw new CmsDbSqlException(Messages.get().container( 2023 Messages.ERR_GENERIC_SQL_1, 2024 CmsDbSqlException.getErrorQuery(stmt)), e); 2025 } finally { 2026 m_sqlManager.closeAll(dbc, conn, stmt, res); 2027 } 2028 return (projects); 2029 } 2030 2031 2034 public List readProjectsForUser(CmsDbContext dbc, CmsUser user) throws CmsDataAccessException { 2035 2036 List projects = new ArrayList (); 2037 ResultSet res = null; 2038 PreparedStatement stmt = null; 2039 Connection conn = null; 2040 2041 try { 2042 conn = m_sqlManager.getConnection(dbc); 2044 stmt = m_sqlManager.getPreparedStatement(conn, "C_PROJECTS_READ_BYUSER"); 2045 2046 stmt.setString(1, user.getId().toString()); 2047 res = stmt.executeQuery(); 2048 2049 while (res.next()) { 2050 projects.add(new CmsProject(res, m_sqlManager)); 2051 } 2052 } catch (SQLException e) { 2053 throw new CmsDbSqlException(Messages.get().container( 2054 Messages.ERR_GENERIC_SQL_1, 2055 CmsDbSqlException.getErrorQuery(stmt)), e); 2056 } finally { 2057 m_sqlManager.closeAll(dbc, conn, stmt, res); 2058 } 2059 return (projects); 2060 } 2061 2062 2065 public List readProjectView(CmsDbContext dbc, int project, String filter) throws CmsDataAccessException { 2066 2067 List resources = new ArrayList (); 2068 CmsResource currentResource = null; 2069 ResultSet res = null; 2070 PreparedStatement stmt = null; 2071 Connection conn = null; 2072 String orderClause = " ORDER BY CMS_T_STRUCTURE.STRUCTURE_ID"; 2073 String whereClause = new String (); 2074 2075 if ("new".equalsIgnoreCase(filter)) { 2077 whereClause = " AND (CMS_T_STRUCTURE.STRUCTURE_STATE=" 2078 + CmsResource.STATE_NEW 2079 + " OR CMS_T_RESOURCES.RESOURCE_STATE=" 2080 + CmsResource.STATE_NEW 2081 + ")"; 2082 } else if ("changed".equalsIgnoreCase(filter)) { 2083 whereClause = " AND (CMS_T_STRUCTURE.STRUCTURE_STATE=" 2084 + CmsResource.STATE_CHANGED 2085 + " OR CMS_T_RESOURCES.RESOURCE_STATE=" 2086 + CmsResource.STATE_CHANGED 2087 + ")"; 2088 } else if ("deleted".equalsIgnoreCase(filter)) { 2089 whereClause = " AND (CMS_T_STRUCTURE.STRUCTURE_STATE=" 2090 + CmsResource.STATE_DELETED 2091 + " OR CMS_T_RESOURCES.RESOURCE_STATE=" 2092 + CmsResource.STATE_DELETED 2093 + ")"; 2094 } else if ("locked".equalsIgnoreCase(filter)) { 2095 whereClause = ""; 2096 } else { 2097 whereClause = " AND (CMS_T_STRUCTURE.STRUCTURE_STATE!=" 2098 + CmsResource.STATE_UNCHANGED 2099 + " OR CMS_T_RESOURCES.RESOURCE_STATE!=" 2100 + CmsResource.STATE_UNCHANGED 2101 + ")"; 2102 } 2103 2104 try { 2105 conn = m_sqlManager.getConnection(dbc); 2107 String query = m_sqlManager.readQuery("C_RESOURCES_PROJECTVIEW") + whereClause + orderClause; 2108 stmt = m_sqlManager.getPreparedStatementForSql(conn, CmsSqlManager.replaceProjectPattern( 2109 CmsProject.ONLINE_PROJECT_ID + 1, 2110 query)); 2111 2112 stmt.setInt(1, project); 2113 res = stmt.executeQuery(); 2114 2115 while (res.next()) { 2116 currentResource = m_driverManager.getVfsDriver().createResource(res, project); 2117 resources.add(currentResource); 2118 } 2119 } catch (SQLException e) { 2120 throw new CmsDbSqlException(Messages.get().container( 2121 Messages.ERR_GENERIC_SQL_1, 2122 CmsDbSqlException.getErrorQuery(stmt)), e); 2123 } finally { 2124 m_sqlManager.closeAll(dbc, conn, stmt, res); 2125 } 2126 2127 return resources; 2128 } 2129 2130 2133 public List readPublishedResources(CmsDbContext dbc, int projectId, CmsUUID publishHistoryId) 2134 throws CmsDataAccessException { 2135 2136 Connection conn = null; 2137 PreparedStatement stmt = null; 2138 ResultSet res = null; 2139 CmsUUID structureId = null; 2140 CmsUUID resourceId = null; 2141 String rootPath = null; 2142 int resourceType = CmsDbUtil.UNKNOWN_ID; 2143 int resourceState = CmsDbUtil.UNKNOWN_ID; 2144 List publishedResources = new ArrayList (); 2145 int siblingCount = CmsDbUtil.UNKNOWN_ID; 2146 int backupTagId = CmsDbUtil.UNKNOWN_ID; 2147 2148 try { 2149 conn = m_sqlManager.getConnection(dbc, projectId); 2150 stmt = m_sqlManager.getPreparedStatement(conn, "C_SELECT_PUBLISHED_RESOURCES"); 2151 stmt.setString(1, publishHistoryId.toString()); 2152 res = stmt.executeQuery(); 2153 2154 while (res.next()) { 2155 structureId = new CmsUUID(res.getString("STRUCTURE_ID")); 2156 resourceId = new CmsUUID(res.getString("RESOURCE_ID")); 2157 rootPath = res.getString("RESOURCE_PATH"); 2158 resourceState = res.getInt("RESOURCE_STATE"); 2159 resourceType = res.getInt("RESOURCE_TYPE"); 2160 siblingCount = res.getInt("SIBLING_COUNT"); 2161 backupTagId = res.getInt("PUBLISH_TAG"); 2162 2163 publishedResources.add(new CmsPublishedResource( 2164 structureId, 2165 resourceId, 2166 backupTagId, 2167 rootPath, 2168 resourceType, 2169 structureId.isNullUUID() ? false : CmsFolder.isFolderType(resourceType), 2170 resourceState, 2171 siblingCount)); 2172 } 2173 } catch (SQLException e) { 2174 throw new CmsDbSqlException(Messages.get().container( 2175 Messages.ERR_GENERIC_SQL_1, 2176 CmsDbSqlException.getErrorQuery(stmt)), e); 2177 } finally { 2178 m_sqlManager.closeAll(dbc, conn, stmt, res); 2179 } 2180 2181 return publishedResources; 2182 } 2183 2184 2187 public String readStaticExportPublishedResourceParameters( 2188 CmsDbContext dbc, 2189 CmsProject currentProject, 2190 String rfsName) throws CmsDataAccessException { 2191 2192 String returnValue = null; 2193 Connection conn = null; 2194 PreparedStatement stmt = null; 2195 ResultSet res = null; 2196 2197 try { 2198 conn = m_sqlManager.getConnection(dbc, currentProject.getId()); 2199 stmt = m_sqlManager.getPreparedStatement(conn, "C_STATICEXPORT_READ_PUBLISHED_LINK_PARAMETERS"); 2200 stmt.setString(1, rfsName); 2201 res = stmt.executeQuery(); 2202 if (res.next()) { 2204 returnValue = res.getString(1); 2205 } 2206 } catch (SQLException e) { 2207 throw new CmsDbSqlException(Messages.get().container( 2208 Messages.ERR_GENERIC_SQL_1, 2209 CmsDbSqlException.getErrorQuery(stmt)), e); 2210 } finally { 2211 m_sqlManager.closeAll(dbc, conn, stmt, res); 2212 } 2213 2214 return returnValue; 2215 } 2216 2217 2220 public List readStaticExportResources( 2221 CmsDbContext dbc, 2222 CmsProject currentProject, 2223 int parameterResources, 2224 long timestamp) throws CmsDataAccessException { 2225 2226 Connection conn = null; 2227 PreparedStatement stmt = null; 2228 ResultSet res = null; 2229 List returnValue = new ArrayList (); 2230 2231 if (parameterResources == CmsStaticExportManager.EXPORT_LINK_WITHOUT_PARAMETER) { 2232 timestamp = 0; 2233 } 2234 try { 2235 conn = m_sqlManager.getConnection(dbc, currentProject.getId()); 2236 stmt = m_sqlManager.getPreparedStatement(conn, "C_STATICEXPORT_READ_ALL_PUBLISHED_LINKS"); 2237 stmt.setInt(1, parameterResources); 2238 stmt.setLong(2, timestamp); 2239 res = stmt.executeQuery(); 2240 while (res.next()) { 2242 returnValue.add(res.getString(1)); 2243 } 2244 } catch (SQLException e) { 2245 throw new CmsDbSqlException(Messages.get().container( 2246 Messages.ERR_GENERIC_SQL_1, 2247 CmsDbSqlException.getErrorQuery(stmt)), e); 2248 } finally { 2249 m_sqlManager.closeAll(dbc, conn, stmt, res); 2250 } 2251 2252 return returnValue; 2253 } 2254 2255 2258 public void unmarkProjectResources(CmsDbContext dbc, CmsProject project) throws CmsDataAccessException { 2259 2260 2262 Connection conn = null; 2263 PreparedStatement stmt = null; 2264 try { 2265 conn = m_sqlManager.getConnection(dbc, project.getId()); 2266 stmt = m_sqlManager.getPreparedStatement(conn, "C_RESOURCES_UNMARK"); 2267 stmt.setInt(1, project.getId()); 2269 stmt.executeUpdate(); 2270 } catch (SQLException e) { 2271 throw new CmsDbSqlException(Messages.get().container( 2272 Messages.ERR_GENERIC_SQL_1, 2273 CmsDbSqlException.getErrorQuery(stmt)), e); 2274 } finally { 2275 m_sqlManager.closeAll(dbc, conn, stmt, null); 2276 } 2277 } 2278 2279 2282 public void writeProject(CmsDbContext dbc, CmsProject project) throws CmsDataAccessException { 2283 2284 if (CmsStringUtil.isEmptyOrWhitespaceOnly(project.getDescription())) { 2285 project.setDescription(" "); 2286 } 2287 Connection conn = null; 2288 PreparedStatement stmt = null; 2289 2290 try { 2291 conn = m_sqlManager.getConnection(dbc); 2293 2294 stmt = m_sqlManager.getPreparedStatement(conn, "C_PROJECTS_WRITE"); 2295 stmt.setString(1, project.getDescription()); 2296 stmt.setString(2, project.getGroupId().toString()); 2297 stmt.setString(3, project.getManagerGroupId().toString()); 2298 stmt.setInt(4, project.getFlags()); 2299 stmt.setInt(5, project.getType()); 2300 stmt.setInt(6, project.getId()); 2301 stmt.executeUpdate(); 2302 } catch (SQLException e) { 2303 throw new CmsDbSqlException(Messages.get().container( 2304 Messages.ERR_GENERIC_SQL_1, 2305 CmsDbSqlException.getErrorQuery(stmt)), e); 2306 } finally { 2307 m_sqlManager.closeAll(dbc, conn, stmt, null); 2308 } 2309 } 2310 2311 2314 public void writePublishHistory( 2315 CmsDbContext dbc, 2316 CmsProject currentProject, 2317 CmsUUID publishId, 2318 CmsPublishedResource resource) throws CmsDataAccessException { 2319 2320 Connection conn = null; 2321 PreparedStatement stmt = null; 2322 2323 try { 2324 conn = m_sqlManager.getConnection(dbc, currentProject.getId()); 2325 stmt = m_sqlManager.getPreparedStatement(conn, "C_RESOURCES_WRITE_PUBLISH_HISTORY"); 2326 stmt.setInt(1, resource.getBackupTagId()); 2327 stmt.setString(2, resource.getStructureId().toString()); 2328 stmt.setString(3, resource.getResourceId().toString()); 2329 stmt.setString(4, resource.getRootPath()); 2330 stmt.setInt(5, resource.getState()); 2331 stmt.setInt(6, resource.getType()); 2332 stmt.setString(7, publishId.toString()); 2333 stmt.setInt(8, resource.getSiblingCount()); 2334 stmt.executeUpdate(); 2335 } catch (SQLException e) { 2336 throw new CmsDbSqlException(Messages.get().container( 2337 Messages.ERR_GENERIC_SQL_1, 2338 CmsDbSqlException.getErrorQuery(stmt)), e); 2339 } finally { 2340 m_sqlManager.closeAll(dbc, conn, stmt, null); 2341 } 2342 } 2343 2344 2347 public void writeStaticExportPublishedResource( 2348 CmsDbContext dbc, 2349 CmsProject currentProject, 2350 String resourceName, 2351 int linkType, 2352 String linkParameter, 2353 long timestamp) throws CmsDataAccessException { 2354 2355 Connection conn = null; 2356 PreparedStatement stmt = null; 2357 ResultSet res = null; 2358 int returnValue = 0; 2359 try { 2361 conn = m_sqlManager.getConnection(dbc, currentProject.getId()); 2362 stmt = m_sqlManager.getPreparedStatement(conn, "C_STATICEXPORT_READ_PUBLISHED_RESOURCES"); 2363 stmt.setString(1, resourceName); 2364 res = stmt.executeQuery(); 2365 if (res.next()) { 2366 returnValue = res.getInt(1); 2367 } 2368 } catch (SQLException e) { 2369 throw new CmsDbSqlException(Messages.get().container( 2370 Messages.ERR_GENERIC_SQL_1, 2371 CmsDbSqlException.getErrorQuery(stmt)), e); 2372 } finally { 2373 m_sqlManager.closeAll(dbc, conn, stmt, res); 2374 } 2375 2376 if (returnValue == 0) { 2378 try { 2379 conn = m_sqlManager.getConnection(dbc, currentProject.getId()); 2380 stmt = m_sqlManager.getPreparedStatement(conn, "C_STATICEXPORT_WRITE_PUBLISHED_LINKS"); 2381 stmt.setString(1, new CmsUUID().toString()); 2382 stmt.setString(2, resourceName); 2383 stmt.setInt(3, linkType); 2384 stmt.setString(4, linkParameter); 2385 stmt.setLong(5, timestamp); 2386 stmt.executeUpdate(); 2387 } catch (SQLException e) { 2388 throw new CmsDbSqlException(Messages.get().container(Messages.ERR_GENERIC_SQL_1, stmt), e); 2389 } finally { 2390 m_sqlManager.closeAll(dbc, conn, stmt, null); 2391 } 2392 } 2393 } 2394 2395 2398 protected void finalize() throws Throwable { 2399 2400 try { 2401 m_sqlManager = null; 2402 m_driverManager = null; 2403 } catch (Throwable t) { 2404 } 2406 super.finalize(); 2407 } 2408 2409 2417 protected void internalResetResourceState(CmsDbContext dbc, CmsResource resource) throws CmsDataAccessException { 2418 2419 try { 2420 2421 if (resource.getState() != CmsResource.STATE_UNCHANGED) { 2423 resource.setState(CmsResource.STATE_UNCHANGED); 2424 m_driverManager.getVfsDriver().writeResourceState( 2425 dbc, 2426 dbc.currentProject(), 2427 resource, 2428 CmsDriverManager.UPDATE_ALL); 2429 } 2430 2431 2435 } catch (CmsDataAccessException e) { 2436 if (LOG.isErrorEnabled()) { 2437 LOG.error(Messages.get().getBundle().key( 2438 Messages.LOG_ERROR_RESETTING_RESOURCE_STATE_1, 2439 resource.getRootPath()), e); 2440 } 2441 throw e; 2442 } 2443 } 2444} | Popular Tags |