1<?php 2 3namespace ComboStrap; 4 5/** 6 * First class to migrate to a combo file system implementation 7 * in the database 8 * 9 * The function are here to locate where the code should go. 10 */ 11class ComboFs 12{ 13 14 const CANONICAL = "combo-file-system"; 15 16 /** 17 * @param Path $path - the path (no more markup, ultimately, it should be a CombPath) 18 * @return void 19 */ 20 public static function createIfNotExists(Path $path) 21 { 22 23 $markup = MarkupPath::createPageFromPathObject($path); 24 try { 25 $databasePage = new DatabasePageRow(); 26 try { 27 $databasePage->getDatabaseRowFromPage($markup); 28 } catch (ExceptionNotExists $e) { 29 $pageId = PageId::generateAndStorePageId($markup); 30 $databasePage->upsertAttributes([PageId::getPersistentName() => $pageId]); 31 } 32 } catch (ExceptionCompile $e) { 33 throw new ExceptionRuntimeInternal("Unable to store the page id in the database. Message:" . $e->getMessage(), self::CANONICAL, 1, $e); 34 } 35 } 36 37 public static function delete(Path $path) 38 { 39 $markup = MarkupPath::createPageFromPathObject($path); 40 try { 41 DatabasePageRow::getOrCreateFromPageObject($markup) 42 ->deleteIfExist(); 43 } catch (ExceptionSqliteNotAvailable $e) { 44 // 45 } 46 } 47} 48