| @@ 1655-1726 (lines=72) @@ | ||
| 1652 | $dsShell = preg_replace(array('/<!--[\w ]++-->/', '/(\t+[\r\n]){2,}/', '/(\r\n){2,}/'), '$1', $dsShell); |
|
| 1653 | ||
| 1654 | // Write the file |
|
| 1655 | if (!is_writable(dirname($file)) || !General::writeFile($file, $dsShell, |
|
| 1656 | Symphony::Configuration()->get('write_mode', 'file'), 'w', true) |
|
| 1657 | ) { |
|
| 1658 | $this->pageAlert( |
|
| 1659 | __('Failed to write Data source to disk.') |
|
| 1660 | . ' ' . __('Please check permissions on %s.', array('<code>/workspace/data-sources</code>')), |
|
| 1661 | Alert::ERROR |
|
| 1662 | ); |
|
| 1663 | ||
| 1664 | // Write successful |
|
| 1665 | } else { |
|
| 1666 | if (function_exists('opcache_invalidate')) { |
|
| 1667 | opcache_invalidate($file, true); |
|
| 1668 | } |
|
| 1669 | ||
| 1670 | // Attach this datasources to pages |
|
| 1671 | $connections = $fields['connections']; |
|
| 1672 | ResourceManager::setPages(ResourceManager::RESOURCE_TYPE_DS, |
|
| 1673 | is_null($existing_handle) ? $classname : $existing_handle, $connections); |
|
| 1674 | ||
| 1675 | // If the datasource has been updated and the name changed, then adjust all the existing pages that have the old datasource name |
|
| 1676 | if ($queueForDeletion) { |
|
| 1677 | General::deleteFile($queueForDeletion); |
|
| 1678 | ||
| 1679 | // Update pages that use this DS |
|
| 1680 | $pages = PageManager::fetch(false, array('data_sources', 'id'), array( |
|
| 1681 | " |
|
| 1682 | `data_sources` REGEXP '[[:<:]]" . $existing_handle . "[[:>:]]' |
|
| 1683 | " |
|
| 1684 | )); |
|
| 1685 | ||
| 1686 | if (is_array($pages) && !empty($pages)) { |
|
| 1687 | foreach ($pages as $page) { |
|
| 1688 | $page['data_sources'] = preg_replace('/\b' . $existing_handle . '\b/i', $classname, |
|
| 1689 | $page['data_sources']); |
|
| 1690 | ||
| 1691 | PageManager::edit($page['id'], $page); |
|
| 1692 | } |
|
| 1693 | } |
|
| 1694 | } |
|
| 1695 | ||
| 1696 | if ($this->_context['action'] === 'new') { |
|
| 1697 | /** |
|
| 1698 | * After creating the Datasource, the path to the Datasource file is provided |
|
| 1699 | * |
|
| 1700 | * @delegate DatasourcePostCreate |
|
| 1701 | * @since Symphony 2.2 |
|
| 1702 | * @param string $context |
|
| 1703 | * '/blueprints/datasources/' |
|
| 1704 | * @param string $file |
|
| 1705 | * The path to the Datasource file |
|
| 1706 | */ |
|
| 1707 | Symphony::ExtensionManager()->notifyMembers('DatasourcePostCreate', '/blueprints/datasources/', |
|
| 1708 | array( |
|
| 1709 | 'file' => $file |
|
| 1710 | )); |
|
| 1711 | } else { |
|
| 1712 | /** |
|
| 1713 | * After editing the Datasource, the path to the Datasource file is provided |
|
| 1714 | * |
|
| 1715 | * @delegate DatasourcePostEdit |
|
| 1716 | * @since Symphony 2.2 |
|
| 1717 | * @param string $context |
|
| 1718 | * '/blueprints/datasources/' |
|
| 1719 | * @param string $file |
|
| 1720 | * The path to the Datasource file |
|
| 1721 | * @param string $previous_file |
|
| 1722 | * The path of the previous Datasource file in the case where a Datasource may |
|
| 1723 | * have been renamed. To get the handle from this value, see |
|
| 1724 | * `DatasourceManager::__getHandleFromFilename` |
|
| 1725 | */ |
|
| 1726 | Symphony::ExtensionManager()->notifyMembers('DatasourcePostEdit', '/blueprints/datasources/', |
|
| 1727 | array( |
|
| 1728 | 'file' => $file, |
|
| 1729 | 'previous_file' => ($queueForDeletion) ? $queueForDeletion : null |
|
| @@ 577-646 (lines=70) @@ | ||
| 574 | } |
|
| 575 | ||
| 576 | // Write the file |
|
| 577 | if (!is_writable(dirname($file)) || !General::writeFile($file, $eventShell, |
|
| 578 | Symphony::Configuration()->get('write_mode', 'file')) |
|
| 579 | ) { |
|
| 580 | $this->pageAlert( |
|
| 581 | __('Failed to write Event to disk.') |
|
| 582 | . ' ' . __('Please check permissions on %s.', array('<code>/workspace/events</code>')), |
|
| 583 | Alert::ERROR |
|
| 584 | ); |
|
| 585 | ||
| 586 | // Write successful |
|
| 587 | } else { |
|
| 588 | if (function_exists('opcache_invalidate')) { |
|
| 589 | opcache_invalidate($file, true); |
|
| 590 | } |
|
| 591 | ||
| 592 | // Attach this event to pages |
|
| 593 | $connections = $fields['connections']; |
|
| 594 | ResourceManager::setPages(ResourceManager::RESOURCE_TYPE_EVENT, |
|
| 595 | is_null($existing_handle) ? $classname : $existing_handle, $connections); |
|
| 596 | ||
| 597 | if ($queueForDeletion) { |
|
| 598 | General::deleteFile($queueForDeletion); |
|
| 599 | ||
| 600 | $pages = PageManager::fetch(false, array('events', 'id'), array( |
|
| 601 | " |
|
| 602 | `events` REGEXP '[[:<:]]" . $existing_handle . "[[:>:]]' |
|
| 603 | " |
|
| 604 | )); |
|
| 605 | ||
| 606 | if (is_array($pages) && !empty($pages)) { |
|
| 607 | foreach ($pages as $page) { |
|
| 608 | $page['events'] = preg_replace('/\b' . $existing_handle . '\b/i', $classname, |
|
| 609 | $page['events']); |
|
| 610 | ||
| 611 | PageManager::edit($page['id'], $page); |
|
| 612 | } |
|
| 613 | } |
|
| 614 | } |
|
| 615 | ||
| 616 | if ($this->_context['action'] === 'new') { |
|
| 617 | /** |
|
| 618 | * After creating the Event, the path to the Event file is provided |
|
| 619 | * |
|
| 620 | * @delegate EventPostCreate |
|
| 621 | * @since Symphony 2.2 |
|
| 622 | * @param string $context |
|
| 623 | * '/blueprints/events/' |
|
| 624 | * @param string $file |
|
| 625 | * The path to the Event file |
|
| 626 | */ |
|
| 627 | Symphony::ExtensionManager()->notifyMembers('EventPostCreate', '/blueprints/events/', array( |
|
| 628 | 'file' => $file |
|
| 629 | )); |
|
| 630 | } else { |
|
| 631 | /** |
|
| 632 | * After editing the Event, the path to the Event file is provided |
|
| 633 | * |
|
| 634 | * @delegate EventPostEdit |
|
| 635 | * @since Symphony 2.2 |
|
| 636 | * @param string $context |
|
| 637 | * '/blueprints/events/' |
|
| 638 | * @param string $file |
|
| 639 | * The path to the Event file |
|
| 640 | * @param string $previous_file |
|
| 641 | * The path of the previous Event file in the case where an Event may |
|
| 642 | * have been renamed. To get the handle from this value, see |
|
| 643 | * `EventManager::__getHandleFromFilename` |
|
| 644 | */ |
|
| 645 | Symphony::ExtensionManager()->notifyMembers('EventPostEdit', '/blueprints/events/', array( |
|
| 646 | 'file' => $file, |
|
| 647 | 'previous_file' => ($queueForDeletion) ? $queueForDeletion : null |
|
| 648 | )); |
|
| 649 | } |
|