<NME> TheArchitectController.php
<BEF> <?php

namespace Craft;

/**
 * TheArchitectController.
 */
class TheArchitectController extends BaseController
{
    // Public Methods
    // =========================================================================

    /**
     * {@inheritdoc} BaseController::init()
     *
     * @throws HttpException
     */
    public function init()
    {
        // All section actions require an admin
        craft()->userSession->requireAdmin();
    }

    /**
     * actionBlueprint [list the exportable items].
     */
    public function actionBlueprint()
    {
        $variables = array(
            'assetSources' => craft()->assetSources->getAllSources(),
            'assetTransforms' => craft()->assetTransforms->getAllTransforms(),
        );

        craft()->templates->includeJsResource('thearchitect/js/diff.min.js');
        craft()->templates->includeJsResource('thearchitect/js/thearchitect.js');
        craft()->templates->includeCssResource('thearchitect/css/thearchitect.css');

        $this->renderTemplate('thearchitect/blueprint', $variables);
    }

    /**
     * actionConstructBlueprint.
     */
    public function actionConstructBlueprint()
    {
        // Prevent GET Requests
        $this->requirePostRequest();

        $post = craft()->request->getPost();

        $output = craft()->theArchitect->exportConstruct($post);

        // If the output is empty redirect back the the export page
        if ($output == []) {
            $this->redirect('thearchitect/blueprint');
        }
        // Else display the output data as json for the user to copy
        else {
        if (isset($post['sectionSelection'])) {
            foreach ($post['sectionSelection'] as $id) {
                $section = craft()->sections->getSectionById($id);

                $tmpSection = [
                    "name" => $section->attributes["name"],
    }

    /**
     * actionBlueprint [list the exportable items].
     */
    public function actionConvert()
    {
        $variables = array(
            'assetSources' => craft()->assetSources->getAllSources(),
            'assetTransforms' => craft()->assetTransforms->getAllTransforms(),
        );

        craft()->templates->includeJsResource('thearchitect/js/diff.min.js');
        craft()->templates->includeJsResource('thearchitect/js/thearchitect.js');
        craft()->templates->includeCssResource('thearchitect/css/thearchitect.css');

        $this->renderTemplate('thearchitect/convert', $variables);
    }

    /**
     * actionConvert [ TODO ].
     */
    public function actionRecode()
    {
        // Prevent GET Requests
        $this->requirePostRequest();

        $post = craft()->request->getPost();

        list($newObject, $allFields, $fields, $similarFields) = craft()->theArchitect->exportMatrixAsNeo($post);

        $variables = array(
            'json' => json_encode($newObject, /*JSON_NUMERIC_CHECK | */JSON_PRETTY_PRINT),
            'tab' => 'tab5',
            'oldFieldCount' => sizeof($allFields),
            'newFieldCount' => sizeof($fields),
            'similarFields' => $similarFields,
        );

        craft()->templates->includeJsResource('thearchitect/js/diff.min.js');
        craft()->templates->includeJsResource('thearchitect/js/thearchitect.js');
        craft()->templates->includeCssResource('thearchitect/css/thearchitect.css');

        $this->renderTemplate('thearchitect/output', $variables);
    }

    /**
        if (isset($post['fieldSelection'])) {
            foreach ($post['fieldSelection'] as $id) {
                $field = craft()->fields->getFieldById($id);

                if (!in_array($field->group->name, $groups)) {
                    array_push($groups, $field->group->name);
        if (file_exists($masterJson)) {
            $exportTime = filemtime($masterJson);
        } else {
            $exportTime = null;
        }

        if (file_exists($masterJson)) {
            list($dbAddedIDs, $dbUpdatedIDs, $dbDeleteIDs, $modelAddedIDs, $modelUpdatedIDs, $modelDeleteIDs) = craft()->theArchitect->getAddedUpdatedDeletedIds(file_get_contents($masterJson));
        }
                    "typesettings" => $field->settings
                ];

                if ($field->type == 'Neo') {
                    $blockTypes = craft()->neo->getBlockTypesByFieldId($id);
                    $blockCount = 0;
    public function actionGenerateKey()
    {
        // Generate a new API key for import / export url calls
        craft()->plugins->savePluginSettings(craft()->plugins->getPlugin('theArchitect'), array('apiKey' => craft()->theArchitect->generateUUID4()));

        $this->redirect('thearchitect/migrations');
    }

    /**
     * actionConstructList [list the files inside the `config.jsonPath` folder].
     */
    public function actionConstructList()
    {
        $files = array();
        $jsonPath = craft()->path->getConfigPath().'thearchitect/';

        if (file_exists($jsonPath) && is_dir($jsonPath) && $handle = opendir($jsonPath)) {
            while (false !== ($entry = readdir($handle))) {
                if ($entry != '.' && $entry != '..' && $entry != '_master_.json' && strtolower(pathinfo($entry, PATHINFO_EXTENSION)) == 'json') {
                    $files[] = $entry;
                }
            }
            closedir($handle);
        }

        natsort($files);

        $groups = craft()->fields->getAllGroups();
        $fields = craft()->fields->getAllFields();
        $sections = craft()->sections->getAllSections();

        foreach ($fields as $field) {
            if ($field->type == 'Matrix') {
                $blockTypes = craft()->matrix->getBlockTypesByFieldId($field->id);
                foreach ($blockTypes as $blockType) {
                    $blockType->getFields();
                }
            }
        }

        $variables = array(
            'files' => $files,
        );

        $this->renderTemplate('thearchitect/files', $variables);
    }

    /**
     * actionConstructLoad [load the selected file for review before processing].
     */
    public function actionConstructLoad()
    {
        // Prevent GET Requests
        $this->requirePostRequest();

        $fileName = craft()->request->getRequiredPost('fileName');
        $jsonPath = craft()->path->getConfigPath().'thearchitect/';

        $filePath = $jsonPath.$fileName;

        if (file_exists($filePath)) {
            $json = file_get_contents($filePath);

            $variables = array(
                'json' => $json,
                'filename' => $fileName,
            );

            $this->renderTemplate('thearchitect/index', $variables);
        }
    }

    /**
     * actionConstruct.
     */
    public function actionConstruct()
    {
        // Prevent GET Requests
        $this->requirePostRequest();

        $json = craft()->request->getRequiredPost('json');

        if ($json) {
            $notice = craft()->theArchitect->parseJson($json);

            $variables = array(
                'json' => $json,
                'result' => $notice,
            );

            $this->renderTemplate('thearchitect/index', $variables);
        }
    }
}

<MSG> Sources converted into handles

* Assets Sources
* Categories Source
* Entries Sources
* Tags Source
* Users Sources

<DFF> @@ -59,6 +59,7 @@ class TheArchitectController extends BaseController {
         if (isset($post['sectionSelection'])) {
             foreach ($post['sectionSelection'] as $id) {
                 $section = craft()->sections->getSectionById($id);
+                if ($section === null) continue;
 
                 $tmpSection = [
                     "name" => $section->attributes["name"],
@@ -112,6 +113,7 @@ class TheArchitectController extends BaseController {
         if (isset($post['fieldSelection'])) {
             foreach ($post['fieldSelection'] as $id) {
                 $field = craft()->fields->getFieldById($id);
+                if ($field === null) continue;
 
                 if (!in_array($field->group->name, $groups)) {
                     array_push($groups, $field->group->name);
@@ -127,6 +129,57 @@ class TheArchitectController extends BaseController {
                     "typesettings" => $field->settings
                 ];
 
+                if ($field->type == 'Assets') {
+                    if ($tmpField["typesettings"]["sources"]) {
+                        foreach ($tmpField["typesettings"]["sources"] as $key => $value) {
+                            if (substr($value, 0, 7) == 'folder:') {
+                                $source = craft()->assetSources->getSourceById(intval(substr($value, 7)));
+                                $tmpField["typesettings"]["sources"][$key] = $source->handle;
+                            }
+                        }
+                    }
+                }
+
+                if ($field->type == 'Categories') {
+                    if ($tmpField["typesettings"]["source"]) {
+                        if (substr($tmpField["typesettings"]["source"], 0, 6) == 'group:') {
+                            $category = craft()->categories->getGroupById(intval(substr($tmpField["typesettings"]["source"], 6)));
+                            $tmpField["typesettings"]["source"] = $category->handle;
+                        }
+                    }
+                }
+
+                if ($field->type == 'Entries') {
+                    if ($tmpField["typesettings"]["sources"]) {
+                        foreach ($tmpField["typesettings"]["sources"] as $key => $value) {
+                            if (substr($value, 0, 8) == 'section:') {
+                                $source = craft()->sections->getSectionById(intval(substr($value, 8)));
+                                $tmpField["typesettings"]["sources"][$key] = $source->handle;
+                            }
+                        }
+                    }
+                }
+
+                if ($field->type == 'Tags') {
+                    if ($tmpField["typesettings"]["source"]) {
+                        if (substr($tmpField["typesettings"]["source"], 0, 9) == 'taggroup:') {
+                            $category = craft()->tags->getTagGroupById(intval(substr($tmpField["typesettings"]["source"], 9)));
+                            $tmpField["typesettings"]["source"] = $category->handle;
+                        }
+                    }
+                }
+
+                if ($field->type == 'Users') {
+                    if ($tmpField["typesettings"]["sources"]) {
+                        foreach ($tmpField["typesettings"]["sources"] as $key => $value) {
+                            if (substr($value, 0, 6) == 'group:') {
+                                $source = craft()->userGroups->getGroupById(intval(substr($value, 6)));
+                                $tmpField["typesettings"]["sources"][$key] = $source->handle;
+                            }
+                        }
+                    }
+                }
+
                 if ($field->type == 'Neo') {
                     $blockTypes = craft()->neo->getBlockTypesByFieldId($id);
                     $blockCount = 0;

Sources converted into handles