-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ticktackk
committed
Feb 12, 2018
1 parent
7c9756b
commit a447abc
Showing
137 changed files
with
1,806 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace TickTackk\DeveloperTools\Job; | ||
|
||
use \XF\Job\AbstractJob; | ||
use \XF\Mvc\Entity\Entity; | ||
use \TickTackk\DeveloperTools\Git\GitRepository; | ||
|
||
class Commit extends AbstractJob | ||
{ | ||
public function run($maxRunTime) | ||
{ | ||
$actionType = $this->data['actionType']; | ||
$typeDir = $this->data['typeDir']; | ||
$repoDir = $this->data['repoDir']; | ||
$entityClone = $this->data['entityClone']; | ||
$delayedJob = $this->data['delayedJob']; | ||
$isUpdate = $this->data['isUpdate']; | ||
|
||
if ($isUpdate && $actionType == 'export') | ||
{ | ||
$actionType = 'change'; | ||
} | ||
|
||
if ($delayedJob) | ||
{ | ||
foreach ($entityClone as $key => $value) | ||
{ | ||
if (strpos($value, '\__phrase') || (strcmp(substr($value, strlen($value) - strlen('\__phrase')), '\__phrase') === 0)) | ||
{ | ||
$entityClone[$key] = \XF::phrase(str_replace('\__phrase', '', $value))->render(); | ||
} | ||
} | ||
} | ||
|
||
if (is_dir($repoDir)) | ||
{ | ||
$git = new GitRepository($repoDir); | ||
|
||
if ($git->isInitialized()) | ||
{ | ||
$comment = \XF::phrase('developerTools_' . $actionType . '_' . $typeDir . '_commit_template', $entityClone)->render(); | ||
|
||
$options = \XF::options(); | ||
$gitUsername = $options->developerTools_git_username; | ||
$gitEmail = $options->developerTools_git_email; | ||
|
||
if (!empty($git->config()->get('user.name'))) | ||
{ | ||
$git->config()->add('user.name', $gitUsername)->execute(); | ||
} | ||
if (!empty($git->config()->get('user.email'))) | ||
{ | ||
$git->config()->add('user.email', $gitEmail)->execute(); | ||
} | ||
|
||
if (empty($git->config()->get('user.name')) || empty($git->config()->get('user.name'))) | ||
{ | ||
return $this->complete(); | ||
} | ||
|
||
$git->add()->execute('*'); | ||
|
||
$git->commit() | ||
->message($comment) | ||
->execute(); | ||
} | ||
} | ||
|
||
return $this->complete(); | ||
} | ||
|
||
public function getStatusMessage() | ||
{ | ||
return ''; | ||
} | ||
|
||
public function canCancel() | ||
{ | ||
return false; | ||
} | ||
|
||
public function canTriggerByChoice() | ||
{ | ||
return false; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
upload/src/addons/TickTackk/DeveloperTools/XF/Behavior/DevOutputWritable.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace TickTackk\DeveloperTools\XF\Behavior; | ||
|
||
use XF\Mvc\Entity\Entity; | ||
|
||
class DevOutputWritable extends XFCP_DevOutputWritable | ||
{ | ||
public function postSave() | ||
{ | ||
$this->cloneEntity($this->entity); | ||
parent::postSave(); | ||
} | ||
|
||
public function preDelete() | ||
{ | ||
$this->cloneEntity($this->entity); | ||
parent::preDelete(); | ||
} | ||
|
||
protected function cloneEntity(Entity $entity) | ||
{ | ||
\XF::app()->developmentOutput()->cloneEntity($entity); | ||
} | ||
} |
181 changes: 181 additions & 0 deletions
181
upload/src/addons/TickTackk/DeveloperTools/XF/DevelopmentOutput.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
<?php | ||
|
||
namespace TickTackk\DeveloperTools\XF; | ||
|
||
use XF\Mvc\Entity\Entity; | ||
use XF\Util\Json; | ||
|
||
class DevelopmentOutput extends XFCP_DevelopmentOutput | ||
{ | ||
protected $repoSuffix = '_repo'; | ||
|
||
public function export(Entity $entity) | ||
{ | ||
$response = parent::export($entity); | ||
|
||
$this->commitOutput('export', $entity); | ||
|
||
return $response; | ||
} | ||
|
||
public function delete(Entity $entity, $new = true) | ||
{ | ||
$response = parent::delete($entity, $new); | ||
|
||
$this->commitOutput('delete', $entity); | ||
|
||
return $response; | ||
} | ||
|
||
public function writeFileToRepo($typeDir, $addOnId, $fileName, $fileContents, array $metadata = [], $verifyChange = true) | ||
{ | ||
if (!$this->enabled || $this->isAddOnSkipped($addOnId)) | ||
{ | ||
return false; | ||
} | ||
|
||
$fullPathForRepo = $this->getFilePathForRepo($typeDir, $addOnId, $fileName); | ||
|
||
if ($verifyChange) | ||
{ | ||
if (!file_exists($fullPathForRepo)) | ||
{ | ||
$write = true; | ||
} | ||
else | ||
{ | ||
$write = file_get_contents($fullPathForRepo) != $fileContents; | ||
} | ||
} | ||
else | ||
{ | ||
$write = true; | ||
} | ||
|
||
if ($write) | ||
{ | ||
\XF\Util\File::writeFile($fullPathForRepo, $fileContents, false); | ||
} | ||
|
||
$metadata['hash'] = $this->hashContents($fileContents); | ||
$this->updateMetadata($typeDir, $addOnId, $fileName, $metadata); | ||
|
||
return true; | ||
} | ||
|
||
public function writeFile($typeDir, $addOnId, $fileName, $fileContents, array $metadata = [], $verifyChange = true) | ||
{ | ||
$response = parent::writeFile($typeDir, $addOnId, $fileName, $fileContents, $metadata, $verifyChange); | ||
|
||
$this->writeFileToRepo($typeDir, $addOnId, $fileName, $fileContents, $metadata, $verifyChange); | ||
|
||
return $response; | ||
} | ||
|
||
public function deleteFileFromRepo($typeDir, $addOnId, $fileName) | ||
{ | ||
if (!$this->enabled || $this->isAddOnSkipped($addOnId)) | ||
{ | ||
return false; | ||
} | ||
|
||
$fullPath = $this->getFilePathForRepo($typeDir, $addOnId, $fileName); | ||
if (file_exists($fullPath)) | ||
{ | ||
unlink($fullPath); | ||
} | ||
|
||
$this->removeMetadata($typeDir, $addOnId, $fileName); | ||
|
||
return true; | ||
} | ||
|
||
public function deleteFile($typeDir, $addOnId, $fileName) | ||
{ | ||
$reponse = parent::deleteFile($typeDir, $addOnId, $fileName); | ||
|
||
$this->deleteFileFromRepo($typeDir, $addOnId, $fileName); | ||
|
||
return $reponse; | ||
} | ||
|
||
public function getFilePathForRepo($typeDir, $addOnId, $fileName) | ||
{ | ||
$ds = \DIRECTORY_SEPARATOR; | ||
$addOnIdDir = $this->prepareAddOnIdForPath($addOnId); | ||
return "{$this->basePath}{$ds}{$addOnIdDir}{$ds}{$this->repoSuffix}{$ds}upload{$ds}src{$ds}addons{$ds}{$addOnIdDir}{$ds}_output{$ds}{$typeDir}{$ds}{$fileName}"; | ||
} | ||
|
||
protected function getMetadataFileNameForRepo($typeDir, $addOnId) | ||
{ | ||
$ds = DIRECTORY_SEPARATOR; | ||
$addOnIdDir = $this->prepareAddOnIdForPath($addOnId); | ||
return "{$this->basePath}{$ds}{$addOnIdDir}{$ds}{$this->repoSuffix}{$ds}upload{$ds}src{$ds}addons{$ds}{$addOnIdDir}{$ds}_output{$ds}{$typeDir}{$ds}{$this->metadataFilename}"; | ||
} | ||
|
||
protected function writeTypeMetadataForRepo($typeDir, $addOnId, array $typeMetadata) | ||
{ | ||
if ($this->isAddOnSkipped($addOnId)) | ||
{ | ||
return; | ||
} | ||
|
||
ksort($typeMetadata); | ||
|
||
$this->metadataCache[$typeDir][$addOnId] = $typeMetadata; | ||
|
||
if ($this->batchMode) | ||
{ | ||
$this->batchesPending[$typeDir][$addOnId] = true; | ||
} | ||
else | ||
{ | ||
$metadataPath = $this->getMetadataFileNameForRepo($typeDir, $addOnId); | ||
file_put_contents($metadataPath, Json::jsonEncodePretty($typeMetadata)); | ||
} | ||
} | ||
|
||
protected function writeTypeMetadata($typeDir, $addOnId, array $typeMetadata) | ||
{ | ||
parent::writeTypeMetadata($typeDir, $addOnId, $typeMetadata); | ||
$this->writeTypeMetadataForRepo($typeDir, $addOnId, $typeMetadata); | ||
} | ||
|
||
public function cloneEntity(Entity $entity) | ||
{ | ||
/** @var \TickTackk\DeveloperTools\XF\DevelopmentOutput\CommitTrait $handler */ | ||
$handler = $this->getHandler($entity->structure()->shortName); | ||
|
||
if (method_exists($handler, 'commitRepo') && | ||
method_exists($handler, 'getOutputCommitData')) | ||
{ | ||
$outputDataKeys = $handler->getOutputCommitData($entity); | ||
if (empty($outputDataKeys)) | ||
{ | ||
return; | ||
} | ||
|
||
$handler->cloneEntity($entity, $outputDataKeys); | ||
} | ||
} | ||
|
||
protected function commitOutput($actionType, Entity $entity) | ||
{ | ||
if (!$this->batchMode) | ||
{ | ||
/** @var \TickTackk\DeveloperTools\XF\DevelopmentOutput\CommitTrait $handler */ | ||
$handler = $this->getHandler($entity->structure()->shortName); | ||
|
||
if (method_exists($handler, 'commitRepo') && | ||
method_exists($handler, 'getOutputCommitData')) | ||
{ | ||
$ds = DIRECTORY_SEPARATOR; | ||
$repoDir = $this->basePath . $ds . $this->prepareAddOnIdForPath($entity->addon_id) . $ds . '_repo'; | ||
|
||
$jobId = $entity->structure()->shortName . '_' . $actionType . '_' . $entity->getEntityId(); | ||
|
||
$handler->commitRepo($jobId, $repoDir, $actionType, $entity->isUpdate()); | ||
} | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
upload/src/addons/TickTackk/DeveloperTools/XF/DevelopmentOutput/AdminNavigation.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace TickTackk\DeveloperTools\XF\DevelopmentOutput; | ||
|
||
use TickTackk\DeveloperTools\XF\DevelopmentOutput\CommitTrait; | ||
use XF\Mvc\Entity\Entity; | ||
|
||
class AdminNavigation extends XFCP_AdminNavigation | ||
{ | ||
use CommitTrait; | ||
|
||
/** | ||
* @param \XF\Entity\AdminNavigation $entity | ||
* | ||
* @return array | ||
*/ | ||
public function getOutputCommitData(Entity $entity) | ||
{ | ||
return [ | ||
'navigation_title' => ['getTitle', '\__phrase'], | ||
'navigation_id' => $entity->getEntityId() | ||
]; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
upload/src/addons/TickTackk/DeveloperTools/XF/DevelopmentOutput/AdminPermission.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace TickTackk\DeveloperTools\XF\DevelopmentOutput; | ||
|
||
use TickTackk\DeveloperTools\XF\DevelopmentOutput\CommitTrait; | ||
use XF\Mvc\Entity\Entity; | ||
|
||
class AdminPermission extends XFCP_AdminPermission | ||
{ | ||
use CommitTrait; | ||
|
||
/** | ||
* @param \XF\Entity\AdminPermission $entity | ||
* | ||
* @return array | ||
*/ | ||
public function getOutputCommitData(Entity $entity) | ||
{ | ||
return [ | ||
'permission_title' => ['getTitle', '\__phrase'], | ||
'permission_id' | ||
]; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
upload/src/addons/TickTackk/DeveloperTools/XF/DevelopmentOutput/AdvertisingPosition.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace TickTackk\DeveloperTools\XF\DevelopmentOutput; | ||
|
||
use TickTackk\DeveloperTools\XF\DevelopmentOutput\CommitTrait; | ||
use XF\Mvc\Entity\Entity; | ||
|
||
class AdvertisingPosition extends XFCP_AdvertisingPosition | ||
{ | ||
use CommitTrait; | ||
|
||
/** | ||
* @param \XF\Entity\AdvertisingPosition $entity | ||
* | ||
* @return array | ||
*/ | ||
public function getOutputCommitData(Entity $entity) | ||
{ | ||
return [ | ||
'position_title' => ['getTitle', '\__phrase'], | ||
'position_id' | ||
]; | ||
} | ||
} |
Oops, something went wrong.