Skip to content

Commit

Permalink
Fix various coding style guide issues
Browse files Browse the repository at this point in the history
  • Loading branch information
TJ Draper committed Sep 7, 2015
1 parent 7c0b3cc commit e35434a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

if (! defined('TEMPLATE_SYNC_NAME')) {
define('TEMPLATE_SYNC_NAME', 'Template Sync');
define('TEMPLATE_SYNC_VER', '1.0.0-b.1');
define('TEMPLATE_SYNC_VER', '1.0.0-b.2');
define('TEMPLATE_SYNC_AUTHOR', 'TJ Draper');
define('TEMPLATE_SYNC_AUTHOR_URL', 'https://buzzingpixel.com');
define('TEMPLATE_SYNC_DESC', 'Delete templates not in the file system');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public function sync_templates()
private function proceedWithSync()
{
ee()->load->model('template_sync_model');
$model = ee()->template_sync_model;

ee()->load->library('template_sync_lib');

$model = ee()->template_sync_model;
$lib = ee()->template_sync_lib;

// Get the file templates from the file system
Expand All @@ -96,12 +96,15 @@ private function proceedWithSync()

// Start arrays
$groupDelete = array();

$templateDelete = array();

$update = array();

$i = 0;

// Loop through the database template groups
foreach($dbTemplates as $dbTemplate) {
foreach ($dbTemplates as $dbTemplate) {
// If the template group is not in the file system, add group to
// delete array and go to next loop iteration
if (! isset($fileTemplates[$dbTemplate['group_name']])) {
Expand All @@ -114,7 +117,7 @@ private function proceedWithSync()
$fileGroupTemplates = $fileTemplates[$dbTemplate['group_name']];

// Loop through the templates in this group
foreach($dbTemplate['templates'] as $template) {
foreach ($dbTemplate['templates'] as $template) {
// If the template is not in file system, add template to delete
// array and go to next loop iteration
if (! isset($fileGroupTemplates[$template['template_name']])) {
Expand All @@ -125,12 +128,15 @@ private function proceedWithSync()

// Set the file system template type
$ext = $fileGroupTemplates[$template['template_name']]['extension'];

$fileType = $typeMap[$ext];

// Add the template type to the update array if not a match
if ($template['template_type'] !== $fileType) {
$update[$i]['template_id'] = $template['template_id'];

$update[$i]['template_type'] = $typeMap[$ext];

$i++;
}
}
Expand Down Expand Up @@ -164,31 +170,36 @@ private function proceedWithSync()

// Set the current order of the DB templates
$dbGroupOrder = array();
foreach($dbTemplates as $dbGroup) {
foreach ($dbTemplates as $dbGroup) {
$dbGroupOrder[] = $dbGroup['group_name'];
}

// Check the order
foreach($fileGroupOrder as $key => $fileOrder) {
foreach ($fileGroupOrder as $key => $fileOrder) {
// If the template names do not match, the DB templates are out
// of order
if ((isset($dbGroupOrder[$key]) && $dbGroupOrder[$key]) !== $fileOrder) {
$i = 0;

$order = array();

// Set the correct order
foreach ($fileTemplates as $fileGroup => $temp) {
foreach ($dbTemplates as $dbGroup) {
if ($dbGroup['group_name'] === $fileGroup) {
$order[$i]['group_id'] = $dbGroup['group_id'];

$order[$i]['group_order'] = $i + 1;

$i++;

break;
}
}
}

$model->updateTemplateGroups($order);

break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ class Template_sync_lib
{
// Acceptable template file extensions
public $templateFileExtensions = array(
'html',
'rss',
'css',
'html',
'js',
'rss',
'xml'
);

// Type mapping
public $typeMap = array(
'html' => 'webpage',
'rss' => 'feed',
'css' => 'css',
'html' => 'webpage',
'js' => 'js',
'rss' => 'feed',
'xml' => 'xml'
);

Expand All @@ -39,13 +39,13 @@ public function getFileTemplates()
$returnFileTemplates = array();

// Set path
$path = rtrim(ee()->config->item('tmpl_file_basepath'), '/') . '/';
$path .= ee()->config->item('site_short_name') . '/';
$path = rtrim(ee()->config->item('tmpl_file_basepath'), '/') . '/' .
ee()->config->item('site_short_name') . '/';

// Get template groups from file system
$templateGroups = $this->dirArray($path);

foreach($templateGroups as $templateGroup) {
foreach ($templateGroups as $templateGroup) {
// Get the name of the template group
$templateGroupName = rtrim($templateGroup, '.group');

Expand All @@ -55,20 +55,22 @@ public function getFileTemplates()
// Get the templates in this group
$templates = $this->dirArray($path . $templateGroup . '/');

foreach($templates as $template) {
foreach ($templates as $template) {
$templatePathInfo = pathinfo($template);

if (
! isset($templatePathInfo['extension']) ||
! in_array(
$templatePathInfo['extension'],

$this->templateFileExtensions
)
) {
continue;
}

$finalTemplates[$templatePathInfo['filename']]['name'] = $templatePathInfo['filename'];

$finalTemplates[$templatePathInfo['filename']]['extension'] =
$templatePathInfo['extension'];
}
Expand All @@ -83,14 +85,16 @@ public function getFileTemplates()
* Scandir array with directories only (unset first two items)
*
* @param string $path
*
* @return array
*/
public function dirArray($path)
{
$dir = scandir($path);

unset($dir[0]);

unset($dir[1]);

return array_values($dir);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function getDbTemplates()

foreach ($templateGroupsQuery as $key => $templateGroup) {
$templateGroups[$templateGroup['group_id']] = $templateGroup;

$templateGroups[$templateGroup['group_id']]['templates'] = array();
}

Expand Down Expand Up @@ -59,6 +60,7 @@ public function deleteTemplateGroups($groupDelete = false)
}

ee()->db->where_in('group_id', $groupDelete);

ee()->db->delete(array(
'templates',
'template_groups'
Expand All @@ -77,6 +79,7 @@ public function deleteTemplates($templateIds = false)
}

ee()->db->where_in('template_id', $templateIds);

ee()->db->delete('templates');
}

Expand Down

0 comments on commit e35434a

Please sign in to comment.