Announcement

Collapse
No announcement yet.

Questions about manual update

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Questions about manual update

    I started according to this guide: https://docs.espocrm.com/administry/upgrading-manually/ The two scripts have to be executed (point 4 in the instructions) and afterupgrade.php (point 10 in the instructions) if the folder (point 3 in the instructions) and copyafter (point 9 in the instructions) in the update -are not available? The script folder is available.

    I have now done the update from 7.3.4 to 7.4.6 manually. There was no copybore and copyefter folder in this update folder. Only the two scripts Beforeupgrade.php and afterupgrade.php. I didn't do these scripts. The manual update apparently worked.

    So far I have been able to use the system as normal. Or do I have to carry out the two scripts, regardless of the copy folder?

    Thank you
    Rene

  • #2
    Hi Rene,

    If you didn't execute BeforeUpgrade and AfterUpgrade something may work wrong. Depending on these scripts, what do they do. It may modify some custom entities. You can inspect these scripts and find out whether they are relevant for your instance.

    Comment


    • #3
      Hi yuri,

      many thanks for the answer.​

      To the update Espocrm-Upgrade-7.4.6-to-7.5.6:

      The Before Script had the following content:​


      PHP Code:
      use Espo\Core\Container;
      use 
      Espo\Entities\User;
      use 
      Espo\ORM\EntityManager;
      use 
      Espo\ORM\Query\DeleteBuilder;

      class 
      BeforeUpgrade
      {
          public function 
      run(Container $container)
          {
              
      $this->deleteDeletedUsers($container->getByClass(EntityManager::class));
          }

          private function 
      deleteDeletedUsers(EntityManager $entityManager): void
          
      {
              
      $query DeleteBuilder::create()
                  ->
      from(User::ENTITY_TYPE)
                  ->
      where(['deleted' => true])
                  ->
      build();

              
      $entityManager->getQueryExecutor()->execute($query);
          }
      }
      ​ 


      And the after -upgrade has the following content:​

      PHP Code:
      use Espo\Core\Container;
      use 
      Espo\Core\Templates\Entities\Event;
      use 
      Espo\Core\Utils\File\Manager as FileManager;
      use 
      Espo\Core\Utils\Json;
      use 
      Espo\Core\Utils\Metadata;

      class 
      AfterUpgrade
      {
          public function 
      run(Container $container): void
          
      {
              
      $this->updateEventMetadata(
                  
      $container->getByClass(Metadata::class),
                  
      $container->getByClass(FileManager::class)
              );
          }

          private function 
      updateEventMetadata(Metadata $metadataFileManager $fileManager): void
          
      {
              
      $defs $metadata->get(['scopes']);

              
      $path1 "application/Espo/Core/Templates/Metadata/Event/selectDefs.json";
              
      $contents1 $fileManager->getContents($path1);
              
      $data1 Json::decode($contents1true);

              
      $primaryFilterClassNameMap = (object) $data1['primaryFilterClassNameMap'];

              foreach (
      $defs as $entityType => $item) {
                  
      $isCustom $item['isCustom'] ?? false;
                  
      $type $item['type'] ?? false;

                  if (!
      $isCustom || $type !== Event::TEMPLATE_TYPE) {
                      continue;
                  }

                  
      $data1 $metadata->getCustom('selectDefs'$entityType) ?? (object) [];
                  
      $data1->primaryFilterClassNameMap $primaryFilterClassNameMap;

                  
      $metadata->saveCustom('selectDefs'$entityType$data1);

                  
      $data2 $metadata->getCustom('scopes'$entityType) ?? (object) [];
                  
      $data2->completedStatusList = ['Held'];
                  
      $data2->canceledStatusList = ['Not Held'];

                  
      $metadata->saveCustom('scopes'$entityType$data2);
              }
          }
      }
      ​ 

      To the update ​EspoCRM-upgrade-7.3.4-to-7.4.6:
      The Before Script had the following content:​

      PHP Code:
      use Espo\Core\Exceptions\Error;
      use 
      Espo\Core\Container;

      class 
      BeforeUpgrade
      {
          private ?
      Container $container null;

          public function 
      run(Container $container)
          {
              
      $this->container $container;

              
      $this->processCheckExtensions();
          }

          private function 
      processCheckExtensions(): void
          
      {
              
      $errorMessageList = [];

              
      $this->processCheckExtension('Advanced Pack''2.13.9'$errorMessageList);
              
      $this->processCheckExtension('Real Estate''1.6.2'$errorMessageList);

              if (!
      count($errorMessageList)) {
                  return;
              }

              
      $message implode("\n\n"$errorMessageList);

              throw new 
      Error($message);
          }

          private function 
      processCheckExtension(string $namestring $minVersion, array &$errorMessageList): void
          
      {
              
      $em $this->container->get('entityManager');

              
      $extension $em->getRDBRepository('Extension')
                  ->
      where([
                      
      'name' => $name,
                      
      'isInstalled' => true,
                  ])
                  ->
      findOne();

              if (!
      $extension) {
                  return;
              }

              
      $version $extension->get('version');

              if (
      version_compare($version$minVersion'>=')) {
                  return;
              }

              
      $message =
                  
      "EspoCRM 7.4 is not compatible with '{$name}' extension of versions lower than {$minVersion}. " .
                  
      "Please upgrade the extension or uninstall it.";

              
      $errorMessageList[] = $message;
          }
      }
      ​ 
      And the after -upgrade has the following content:​

      PHP Code:
      use Espo\Core\Container;
      use 
      Espo\Core\Utils\Metadata;
      use 
      Espo\Core\Templates\Entities\Event;

      class 
      AfterUpgrade
      {
          public function 
      run(Container $container): void
          
      {
              
      $this->updateMetadata($container->get('metadata'));
          }

          private function 
      updateMetadata(Metadata $metadata): void
          
      {
              
      $metadata->set('app''recordId', [
                  
      'length' => 24,
              ]);

              
      $this->fixParent($metadata);
              
      $this->updateEventMetadata($metadata);

              
      $metadata->save();
          }

          private function 
      fixParent(Metadata $metadata): void
          
      {
              foreach (
      $metadata->get(['entityDefs']) as $scope => $defs) {
                  foreach (
      $metadata->get(['entityDefs'$scope'fields']) as $field => $fieldDefs) {
                      
      $custom $metadata->getCustom('entityDefs'$scope);

                      if (!
      $custom) {
                          continue;
                      }

                      if (
                          (
      $fieldDefs['type'] ?? null) === 'linkParent' &&
                          (
      $fieldDefs['notStorable'] ?? false)
                      ) {
                          if (
      $custom?->fields?->$field?->notStorable) {
                              
      $metadata->delete('entityDefs'$scope"fields.{$field}.notStorable");
                          }
                      }
                  }
              }
          }

          private function 
      updateEventMetadata(Metadata $metadata): void
          
      {
              
      $defs $metadata->get(['scopes']);

              foreach (
      $defs as $entityType => $item) {
                  
      $isCustom $item['isCustom'] ?? false;
                  
      $type $item['type'] ?? false;

                  if (!
      $isCustom || $type !== Event::TEMPLATE_TYPE) {
                      continue;
                  }

                  if (!
      is_string($metadata->get(['entityDefs'$entityType'fields''duration''select']))) {
                      continue;
                  }

                  
      $metadata->delete('entityDefs'$entityType'fields.duration.orderBy');

                  
      $metadata->set('entityDefs'$entityType, [
                      
      'fields' => [
                          
      'duration' => [
                              
      'select' => [
                                  
      'select' => "TIMESTAMPDIFF_SECOND:(dateStart, dateEnd)"
                              
      ],
                              
      'order' => [
                                  
      'order' => [["TIMESTAMPDIFF_SECOND:(dateStart, dateEnd)""{direction}"]]
                              ],
                          ]
                      ]
                  ]);
              }
          }
      }
      ​ 
      I don't know whether this is relevant to me or not. How can I find out?

      Best regards​
      Rene

      Comment


      • #4
        Can I still carry out the before and after scripts?​

        Comment

        Working...
        X