Repository: appwrite/appwrite
File: src/Appwrite/Platform/Modules/Functions/Workers/Builds.php (PHP)

Code before:
                            Query::equal('deploymentResourceType', ['site']),
                            Query::equal('trigger', ['manual']),
                            Query::equal('deploymentVcsProviderBranch', ['']),
                            Query::equal("projectInternalId", [$project->getInternalId()])
                        ];

                        $dbForPlatform->forEach('rules', function (Document $rule) use ($dbForPlatform, $deployment) {
                            $rule = $rule
                                ->setAttribute('deploymentId', $deployment->getId())
                                ->setAttribute('deploymentInternalId', $deployment->getInternalId());
                            $dbForPlatform->updateDocument('rules', $rule->getId(), $rule);
                        }, $queries);

                        break;
                }
            }

            if ($resource->getCollection() === 'sites') {
                // VCS branch
                $branchName = $deployment->getAttribute('providerBranch');
                if (!empty($branchName)) {
                    $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
                    $branchPrefix = substr($branchName, 0, 16);
                    if (strlen($branchName) > 16) {
                        $remainingChars = substr($branchName, 16);
                        $branchPrefix .= substr(hash('sha256', $remainingChars), 0, 7);
                    }
                    $resourceProjectHash = substr(hash('sha256', $resource->getId() . $project->getId()), 0, 7);
                    $domain = "branch-{$branchPrefix}-{$resourceProjectHash}.{$sitesDomain}";
                    $ruleId = md5($domain);

                    try {
                        $dbForPlatform->createDocument('rules', new Document([
                            '$id' => $ruleId,
                            'projectId' => $project->getId(),
                            'projectInternalId' => $project->getInternalId(),
                            'domain' => $domain,
                            'type' => 'deployment',
                            'trigger' => 'deployment',
                            'deploymentId' => $deployment->getId(),
                            'deploymentInternalId' => $deployment->getInternalId(),
                            'deploymentResourceType' => 'site',
                            'deploymentResourceId' => $deployment->getId(),
                            'deploymentResourceInternalId' => $deployment->getInternalId(),
                            'deploymentVcsProviderBranch' => $branchName,
                            'status' => 'verified',
                            'certificateId' => '',
                            'search' => implode(' ', [$ruleId, $domain]),
                            'owner' => 'Appwrite',
                            'region' => $project->getAttribute('region')
                        ]));

Review comment (suggestion):
```suggestion
                        $branchPrefix .= '-' . substr(hash('sha256', $remainingChars), 0, 7);
```

Code after:
                            Query::equal('deploymentResourceType', ['site']),
                            Query::equal('trigger', ['manual']),
                            Query::equal('deploymentVcsProviderBranch', ['']),
                            Query::equal("projectInternalId", [$project->getInternalId()])
                        ];

                        $dbForPlatform->forEach('rules', function (Document $rule) use ($dbForPlatform, $deployment) {
                            $rule = $rule
                                ->setAttribute('deploymentId', $deployment->getId())
                                ->setAttribute('deploymentInternalId', $deployment->getInternalId());
                            $dbForPlatform->updateDocument('rules', $rule->getId(), $rule);
                        }, $queries);

                        break;
                }
            }

            if ($resource->getCollection() === 'sites') {
                // VCS branch
                $branchName = $deployment->getAttribute('providerBranch');
                if (!empty($branchName)) {
                    $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
                    $branchPrefix = substr($branchName, 0, 16);
                    if (strlen($branchName) > 16) {
                        $remainingChars = substr($branchName, 16);
                        $branchPrefix .= '-' . substr(hash('sha256', $remainingChars), 0, 7);
                    }
                    $resourceProjectHash = substr(hash('sha256', $resource->getId() . $project->getId()), 0, 7);
                    $domain = "branch-{$branchPrefix}-{$resourceProjectHash}.{$sitesDomain}";
                    $ruleId = md5($domain);

                    try {
                        $dbForPlatform->createDocument('rules', new Document([
                            '$id' => $ruleId,
                            'projectId' => $project->getId(),
                            'projectInternalId' => $project->getInternalId(),
                            'domain' => $domain,
                            'type' => 'deployment',
                            'trigger' => 'deployment',
                            'deploymentId' => $deployment->getId(),
                            'deploymentInternalId' => $deployment->getInternalId(),
                            'deploymentResourceType' => 'site',
                            'deploymentResourceId' => $deployment->getId(),
                            'deploymentResourceInternalId' => $deployment->getInternalId(),
                            'deploymentVcsProviderBranch' => $branchName,
                            'status' => 'verified',
                            'certificateId' => '',
                            'search' => implode(' ', [$ruleId, $domain]),
                            'owner' => 'Appwrite',
                            'region' => $project->getAttribute('region')
                        ]));