Commit af5002aa authored by Florian Bogner's avatar Florian Bogner

feat: Add the option to create demodata during project creation. #775

parent 68f63a24
......@@ -4,6 +4,7 @@
* Create a new project
*
* @param string $params - JSON Array
*
* @return string - Name of the project
*/
QUI::$Ajax->registerFunction(
......@@ -16,6 +17,25 @@ QUI::$Ajax->registerFunction(
$params['lang']
);
if (isset($params['template']) && !empty($params['template'])) {
$Config = QUI::getProjectManager()->getConfig();
$installedTemplates = QUI::getPackageManager()->getInstalled([
'type' => 'quiqqer-template'
]);
$template = $params['template'];
$template = \QUI\Utils\Security\Orthos::removeHTML($template);
$template = \QUI\Utils\Security\Orthos::clearPath($template);
$Config->set($Project->getName(), 'template', $template);
$Config->save();
}
if ($params['demoData']) {
\QUI\Utils\Project::applyDemoDataToProject($Project, $template);
}
return $Project->getName();
},
['params'],
......
......@@ -58,6 +58,16 @@
</select>
</td>
</tr>
<tr class="even">
<td>
<label for="">
{t}quiqqer/system demodata.project.label.template{/t}
</label>
</td>
<td>
<input type="checkbox" name="demoData"></input>
</td>
</tr>
</tbody>
</table>
......
......@@ -64,6 +64,7 @@
"quiqqer\/fontawesome": "*",
"quiqqer\/backendsearch": "1.*|dev-master|dev-dev",
"quiqqer\/requirements": "2.*",
"quiqqer\/demodata":"dev-dev",
"npm-asset\/intl": "1.*",
"npm-asset\/nouislider": "*",
"npm-asset\/mustache": "2.*",
......
......@@ -7,6 +7,7 @@
namespace QUI\Utils;
use QUI;
use QUI\Demodata\Parser\DemoDataParser;
/**
* Class Project
......@@ -52,7 +53,6 @@ class Project
$First->save();
}
// Search
$searchType = 'quiqqer/sitetypes:types/search';
......@@ -62,17 +62,17 @@ class Project
} catch (QUI\Exception $Exception) {
}
$search = $Project->getSitesIds(array(
'where' => array(
$search = $Project->getSitesIds([
'where' => [
'active' => -1,
'type' => $searchType
),
],
'limit' => 1
));
]);
if (empty($search)) {
try {
$searchId = $First->createChild(array(
$searchId = $First->createChild([
'name' => self::parseForUrl(
'quiqqer/quiqqer',
'projects.defaultstructure.search.name',
......@@ -83,7 +83,7 @@ class Project
'projects.defaultstructure.search.title',
$Project
)
));
]);
$Search = new QUI\Projects\Site\Edit($Project, $searchId);
$Search->setAttribute('type', $searchType);
......@@ -94,19 +94,18 @@ class Project
}
}
// Im print / legalnotes / Impressum
$legalNotes = $Project->getSitesIds(array(
'where' => array(
$legalNotes = $Project->getSitesIds([
'where' => [
'active' => -1,
'type' => 'quiqqer/sitetypes:types/legalnotes'
),
],
'limit' => 1
));
]);
if (empty($legalNotes)) {
try {
$legalNoteId = $First->createChild(array(
$legalNoteId = $First->createChild([
'name' => self::parseForUrl(
'quiqqer/quiqqer',
'projects.defaultstructure.legalnotes.name',
......@@ -117,7 +116,7 @@ class Project
'projects.defaultstructure.legalnotes.name',
$Project
)
));
]);
$Legal = new QUI\Projects\Site\Edit($Project, $legalNoteId);
$Legal->setAttribute('type', 'quiqqer/sitetypes:types/legalnotes');
......@@ -129,17 +128,17 @@ class Project
}
// AGB / generalTermsAndConditions
$generalTermsAndConditions = $Project->getSitesIds(array(
'where' => array(
$generalTermsAndConditions = $Project->getSitesIds([
'where' => [
'active' => -1,
'type' => 'quiqqer/sitetypes:types/generalTermsAndConditions'
),
],
'limit' => 1
));
]);
if (empty($generalTermsAndConditions)) {
try {
$generalTermsAndConditionsId = $First->createChild(array(
$generalTermsAndConditionsId = $First->createChild([
'name' => self::parseForUrl(
'quiqqer/quiqqer',
'projects.defaultstructure.generalTermsAndConditions.name',
......@@ -150,7 +149,7 @@ class Project
'projects.defaultstructure.generalTermsAndConditions.name',
$Project
)
));
]);
$GTC = new QUI\Projects\Site\Edit($Project, $generalTermsAndConditionsId);
$GTC->setAttribute('type', 'quiqqer/sitetypes:types/generalTermsAndConditions');
......@@ -161,19 +160,18 @@ class Project
}
}
// Datenschutzerklärung / privacypolicy
$privacyPolicy = $Project->getSitesIds(array(
'where' => array(
$privacyPolicy = $Project->getSitesIds([
'where' => [
'active' => -1,
'type' => 'quiqqer/sitetypes:types/privacypolicy'
),
],
'limit' => 1
));
]);
if (empty($privacyPolicy)) {
try {
$privacyPolicyId = $First->createChild(array(
$privacyPolicyId = $First->createChild([
'name' => self::parseForUrl(
'quiqqer/quiqqer',
'projects.defaultstructure.privacypolicy.name',
......@@ -184,7 +182,7 @@ class Project
'projects.defaultstructure.privacypolicy.name',
$Project
)
));
]);
$Legal = new QUI\Projects\Site\Edit($Project, $privacyPolicyId);
$Legal->setAttribute('type', 'quiqqer/sitetypes:types/privacypolicy');
......@@ -195,6 +193,35 @@ class Project
}
}
/**
* @param QUI\Projects\Project $Project
* @param $templateName
*
*
* @throws QUI\Exception
*/
public static function applyDemoDataToProject(QUI\Projects\Project $Project, $templateName)
{
$TemplatePackage = QUI::getPackageManager()->getInstalledPackage($templateName);
$Parser = new DemoDataParser();
$demoDataArray = [];
if (file_exists($TemplatePackage->getDir().'demodata.xml')) {
$demoDataArray = $Parser->parse($TemplatePackage->getDir().'demodata.xml');
}
if (empty($demoDataArray)) {
throw new QUI\Demodata\Exceptions\UnsupportedException([
'quiqqer/demodata',
'exception.template.unsupported'
]);
}
$DemoData = new QUI\Demodata\DemoData();
$DemoData->apply($Project, $demoDataArray);
}
/**
* parse a locale string that no url error exists
*
......@@ -222,7 +249,7 @@ class Project
*/
public static function validateProjectName($projectName)
{
$forbiddenSigns = array(
$forbiddenSigns = [
'-',
'.',
',',
......@@ -242,21 +269,21 @@ class Project
'=',
'\'',
'"'
);
];
if (preg_match("@[-.,:;#`!§$%&/?<>\=\'\" ]@", $projectName)) {
throw new QUI\Exception(
QUI::getLocale()->get(
'quiqqer/system',
'exception.project.not.allowed.signs',
array(
[
'signs' => implode(' ', $forbiddenSigns)
)
]
),
802
);
}
return true;
}
}
......@@ -5072,6 +5072,9 @@
<locale name="template.project.no.template">
<de><![CDATA[Kein Template verwenden]]></de>
</locale>
<locale name="demodata.project.label.template">
<de><![CDATA[Demodaten installieren]]></de>
</locale>
<locale name="projects.project.site.no.permissions">
<de><![CDATA[Sie besitzen keine Rechte diese Seite anzuzeigen]]></de>
</locale>
......
......@@ -4913,6 +4913,9 @@
<locale name="template.project.no.template">
<en><![CDATA[Do not use a template]]></en>
</locale>
<locale name="demodata.project.label.template">
<en><![CDATA[Install demodata]]></en>
</locale>
<locale name="projects.project.site.no.permissions">
<en><![CDATA[You do not have permission to access this page.]]></en>
</locale>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment