Created
February 15, 2023 12:24
-
-
Save hissy/be14a995ad16bfbe6f91f08d49d5c4f7 to your computer and use it in GitHub Desktop.
[Concrete CMS] [Migration Tool] Inspect file by fvTitle instead of fvFilename
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add below code in application/bootstrap/app.php | |
use Application\Backup\ContentImporter\ValueInspector\InspectionRoutine\FileRoutine; | |
use Application\Backup\ContentImporter\ValueInspector\InspectionRoutine\PictureRoutine; | |
use Concrete\Core\Backup\ContentImporter\ValueInspector\InspectionRoutine\ImageRoutine; | |
use Concrete\Core\Backup\ContentImporter\ValueInspector\InspectionRoutine\PageFeedRoutine; | |
use Concrete\Core\Backup\ContentImporter\ValueInspector\InspectionRoutine\PageRoutine; | |
use Concrete\Core\Backup\ContentImporter\ValueInspector\InspectionRoutine\PageTypeRoutine; | |
if ($app->isInstalled()) { | |
$app->singleton('import/value_inspector', function ($app) { | |
$inspector = $app->make('import/value_inspector/core'); | |
$inspector->registerInspectionRoutine(new PageRoutine()); | |
$inspector->registerInspectionRoutine(new PictureRoutine()); | |
$inspector->registerInspectionRoutine(new FileRoutine()); | |
$inspector->registerInspectionRoutine(new PageFeedRoutine()); | |
$inspector->registerInspectionRoutine(new PageTypeRoutine()); | |
$inspector->registerInspectionRoutine(new ImageRoutine()); | |
return $inspector; | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add below code in application/bootstrap/autoload.php | |
$classLoader = new \Symfony\Component\ClassLoader\Psr4ClassLoader(); | |
$classLoader->addPrefix('Application\\Backup', DIR_APPLICATION . '/' . DIRNAME_CLASSES . '/Backup'); | |
$classLoader->register(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// application/src/Backup/ContentImporter/ValueInspector/Item/FileItem.php | |
namespace Application\Backup\ContentImporter\ValueInspector\Item; | |
use Concrete\Core\File\File; | |
class FileItem extends \Concrete\Core\Backup\ContentImporter\ValueInspector\Item\FileItem | |
{ | |
public function getContentObject() | |
{ | |
$db = \Database::connection(); | |
$fID = null; | |
if ($this->prefix) { | |
$fID = $db->GetOne('select fID from FileVersions where fvPrefix = ? and fvTitle = ?', [$this->prefix, $this->filename]); | |
} else { | |
$fID = $db->GetOne('select fID from FileVersions where fvTitle = ?', [$this->filename]); | |
} | |
if ($fID) { | |
$f = File::getByID($fID); | |
return $f; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// application/src/Backup/ContentImporter/ValueInspector/InspectionRoutine/FileRoutine.php | |
namespace Application\Backup\ContentImporter\ValueInspector\InspectionRoutine; | |
use Application\Backup\ContentImporter\ValueInspector\Item\FileItem; | |
use Concrete\Core\Backup\ContentImporter\ValueInspector\InspectionRoutine\AbstractRegularExpressionRoutine; | |
class FileRoutine extends AbstractRegularExpressionRoutine | |
{ | |
public function getHandle() | |
{ | |
return 'file'; | |
} | |
public function getRegularExpression() | |
{ | |
return '/{ccm:export:file:(.*?)\}/i'; | |
} | |
public function getItem($identifier) | |
{ | |
$prefix = null; | |
$filename = null; | |
if (strpos($identifier, ':') > -1) { | |
list($prefix, $filename) = explode(':', $identifier); | |
} else { | |
$filename = $identifier; | |
} | |
return new FileItem($filename, $prefix); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// application/src/Backup/ContentImporter/ValueInspector/Item/PictureItem.php | |
namespace Application\Backup\ContentImporter\ValueInspector\Item; | |
class PictureItem extends FileItem | |
{ | |
public function getDisplayName() | |
{ | |
return t('Picture'); | |
} | |
public function getContentValue() | |
{ | |
if ($o = $this->getContentObject()) { | |
return '<concrete-picture fID="' . $o->getFileID() . '" />'; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// application/src/Backup/ContentImporter/ValueInspector/InspectionRoutine/PictureRoutine.php | |
namespace Application\Backup\ContentImporter\ValueInspector\InspectionRoutine; | |
use Application\Backup\ContentImporter\ValueInspector\Item\PictureItem; | |
use Concrete\Core\Backup\ContentImporter\ValueInspector\InspectionRoutine\AbstractRegularExpressionRoutine; | |
class PictureRoutine extends AbstractRegularExpressionRoutine | |
{ | |
public function getHandle() | |
{ | |
return 'picture'; | |
} | |
public function getRegularExpression() | |
{ | |
return '/\<concrete-picture\s[^>]*?file\s*=\s*[\'"]([^\'"]*?)[\'"][^>]*?>/i'; | |
} | |
public function getItem($identifier) | |
{ | |
$prefix = null; | |
$filename = null; | |
if (strpos($identifier, ':') > -1) { | |
list($prefix, $filename) = explode(':', $identifier); | |
} else { | |
$filename = $identifier; | |
} | |
return new PictureItem($filename, $prefix); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment