원문 : http://devdocs.magento.com/guides/v2.0/extension-dev-guide/prepare/lifecycle.html
  • 개요(Overview)

    이글은 모듈의 라이프사이클(lifecycle)과 어떻게 그것이 초기화(initialization)되거나 삭제(uninstallation)될 때 실행가능한 클래스를 만드는지를 설명한다. 초기화되거나 삭제되는 동안 이 클래스들은 데이터베이스의 셋업, 업그레이드 그리고 클린업(clean up) 작업 같은 것들을 한다.

    테마 컴포넌트와 랭기지 패키지는 보통 데이터 베이스 스키마를 설치하거나 데이터 베이스에서 데이터를 업데이트하지 않기에 초기화나 삭제업무에대한 걱정은 안해도된다.

    라이프사이클 클래스 룰(Lifecycle class rules)

    당신이 다음의 룰을 따른다면 마젠토는당신이 다른 라이프사이클 스테이지로 훅(hook into the different lifecycle stages )하기위해 시용하는 클래스를 감지할 것이다:

    • 클래스는 당신의 모듈의 루트 디렉토리의 Setup 디렉토리에 적합한 파일네임과함께 있어야한다.  정확한 파일네임은 아래의 구체적인 예들을 참고하라.
    • 클래스는 각 실행단계에 따른 특정한 네임을 사용해야한다.  정확한 클래스 네임을 정하는 것은 아래의 구체적인 예들을 보라.
    • 클래스는 각 실행되는 단계에따른 특정의 클래스 인터페이스를 구현해야한다. 정확한 인터페이스를 사용하려면  아래의 예들을 보다.
    • 모듈에서 사용하는 버전은 우리의 버전 정책( versioning policy)을 따라야한다.

    스키마설치(Schema initialization)

    스키마설치는 모듈이 설치, 재설치, 혹은 업그레이드될때 거치는 첫번째 과정이다.

    스키마설치(Schema installation)

    모듈이 처음 설치될 때 첫번째로 모듈이 하는 것은 자신의 설치클래스(installation class)를 실행하여 스키마를 설치하는 것이다.

    만일 모듈의 schema_version 이 setup_modules 테이블에서 발견된다면 , 이 단계는 스킵(skip)될것이다. 왜냐하면, 모듈 스키마가 이전의 설치(previous installation)에서 벌써 초기화되었다고 가정하기때문이다.

    예를들어 당신이 버전 2.0.0 의 모듈을 설치한다고 할때 이전에 설치한 것이 없다면 스키마 설치(schema installation)가 진행될 것이다. 그렇지않다면, 스키마설치는 스킵되고 모듈은 스키마 업그레이드( schema upgrade. )를 시작할 것이다.

    스키마설치가 진행되는 동안에는 \Magento\Framework\Setup\InstallSchemaInterface를  구현하는 InstallSchema 클래스의  install 함수가 실행될 것이다.

    // File Location: <module_root_directory>/Setup/InstallSchema.php
    
    class \<Vendor>\<Module>\Setup\InstallSchema implements \Magento\Framework\Setup\InstallSchemaInterface
    {
        /**
         * {@inheritdoc}
         */
        public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
        {
            ...
        }
    }
    
    

    스키마업그레이드(Schema upgrade)

    If y만일 마젠토에 이미 모듈의이전버전이 있다면 설치(installation)대신에 업그레이드(upgrade)가 진행된다. 스키마업 그레이드의 목적은 보통 데이터베이스 구조의 업데이트 혹은 패치적용(apply patches)이다.

    예를들어, 모듈의 새로운 버전 2.0.1이 이전버전 2.0.0에 설치된다면 모듈은 스키마 설치(schema installation.)대신에 스키마 업그레이드를 할 것이다.

    스키마업그레이드가 진행되는 동안에는 UpgradeSchema Magento\Framework\Setup\UpgradeSchemaInterface를 구현하는 UpgradeSchema 클래스의 upgrade 함수가 실행될 것이다.

    // Location: <module_root_directory>/Setup/UpgradeSchema.php
    
    class \<Vendor>\<Module>\Setup\UpgradeSchema implements \Magento\Framework\Setup\UpgradeSchemaInterface
    {
        /**
         * {@inheritdoc}
         */
        public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
        {
            ...
        }
    }
    

    리커링 스키마 이벤트(Recurring schema event)

    모듈에 스키마설치 혹은 업그레이드를 할때마다 실행되는 클래스를 모듈에 만들 수 있다. 스키마설치의 마지막 단계에서 코드를 실행하는 목적은 모통 설치 혹은 업그레이드 된 후데이터베이스 스키마의  최종적인  수정작업을 하기위해서다.

    이 이벤트 동안에는 \Magento\Framework\Setup\InstallSchemaInterface를 구현하는 Recurring 클래스의 install 함수가 실행될 것이다.

    // Location: <module_root_directory>/Setup/Recurring.php
    
    class \<Vendor>\<Module>\Setup\Recurring implements \Magento\Framework\Setup\InstallSchemaInterface
    {
        /**
         * {@inheritdoc}
         */
        public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
        {
            ...
        }
    }
    

    데이터 초기화(Data initialization)

    모듈의 스키마가 초기화된 후 모듈은 데이터 초기화를 위해 같은 과정을 진행한다.

    데이터 설치(Data installation)

    스키마설치(schema installation)처럼 이 단계는 모듈의 최초 설치기간에만 실행된다. 데이터설치의 목적은 보통 모듈을 위해 데이터베이스에 초기 데이터를 채우는 것이다.

    데이터설치 동안에는 Magento\Framework\Setup\InstallDataInterface를 구현한 InstallData 클래스의 install 함수가 실행될 것이다.

    // Location: <module_root_directory>/Setup/InstallData.php
    
    class \<Vendor>\<Module>\Setup\InstallData implements \Magento\Framework\Setup\InstallDataInterface
    {
        /**
         * {@inheritdoc}
         */
        public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
        {
            ...
        }
    }
    
    

    데이터 업그레이드(Data upgrade)

    스키마 업그레이드(schema-upgrade) 처럼  데이터 업그레이드는 마젠토가 이전의 설치(previous installation)를 감지했을때 일어난다.  이 단계의 목적은 보통 오염된 데이터를 고치거나 스키마변경에따른 새로운 데이터 필드를 채우는 것이다. 

    데이터 업그레이드 동안에는During a data upgrade, the upgrade function will be executed in the UpgradeData class implementing the Magento\Framework\Setup\UpgradeDataInterface를 구현하는 UpgradeData 클래스의 upgrade 함수가 실행된다.

    //<module_root_directory>/Setup/UpgradeData.php
    
    class \<Vendor>\<Module>\Setup\UpgradeData implements \Magento\Framework\Setup\UpgradeDataInterface
    {
        /**
         * {@inheritdoc}
         */
        public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context);
        {
            ...
        }
    }
    

    리커링 데이터 이벤트(Recurring data event)

    데이터 설치 혹은 업그레이드마다 실행되는 클래스를 만들 수 있다. 이 클래스이 목적은 보통 데이터가 설치 혹은 업그레이드된 후데이터 스토어에 최종적인 수정을 하기 위해서다.

    이 이벤트 기간에는  Magento\Framework\Setup\InstallDataInterface를 구현하는 RecurringData 클래스의 install 함수가 실행된다.

    // Location: <module_root_directory>/Setup/RecurringData.php
    
    class \<Vendor>\<Module>\Setup\RecurringData implements \Magento\Framework\Setup\InstallDataInterface
    {
        /**
         * {@inheritdoc}
         */
        public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
        {
            ...
        }
    }
    

    셋업 리소스 모델(Setup resource models)

    마젠토는 데이터베이스 조작을 돕기위해  ModuleDataSetupInterface 와 ModuleContextInterface 를 제공한다. 그러나, 설치/업그레이드가 너무 복잡하면 모든 로직을 처리하기위해 더 많은 클래스들이 만들어 질 것이다. 이경우에 ModuleDataSetupInterface 리소스를 DB 조작( DB manipulations)을 요구하는 다른 클래스에 넘길 수 있다.

    class InstallData implements InstallDataInterface
    {
        /**
         * @var CustomerFactory
         */
        private $customerSetupFactory;
    
        /**
         * @param CustomerFactory $customerSetupFactory
         */
        public function __construct(CustomerFactory $customerSetupFactory)
        {
            $this->customerSetupFactory = $customerSetupFactory;
        }
    
        /**
         * {@inheritdoc}
         */
        public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
        {
            /** @var Customer $customerSetup */
            $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
    
            $setup->startSetup();
            $customerSetup->installEntities();
            ...
        }
    }
    

    모듈 콘텍스트(Module context)

    설치/업그레이드 클래스에 더 많은 로직을 추가하기 위해서 마젠토가 제공하는  ModuleContextInterface를 사용할 수 있다.  콘텍스트는 현재 모듈버전 같은 클래스에 로직을 더하는데 도움을 줄 수 있는 정보를 제공한다.

    class \Magento\Cms\Setup\InstallData implements \Magento\Framework\Setup\UpgradeDataInterface
    {
       public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
       {
            if (version_compare($context->getVersion(), '1.0.0', '<')) {
                ...
            }
       }
    }
    

    삭제 이벤트(Uninstall event)

    삭제이벤트는 컴포넌트 매니저 혹은 커맨드라인  bin/magento module:uninstall --remove-data <module_name>을 사용하여 모듈을 삭제할 때 시작된다.

    이 단계에서 모듈은 데이터베이스에서 그 존재의 모든 흔적을 지운다: 예. 테이블삭제, 데이터 삭제 혹은 데이터복원(dropping tables, deleting data, or restoring data)

    이 단계에서 Magento\Framework\Setup\UninstallInterface를 구현하는 Uninstall 클래스의 uninstall 함수가 실행된다.

    // Location: <module_root_directory>/Setup/Uninstall.php
    
    class \<Vendor>\<Module>\Setup\Uninstall implements \Magento\Framework\Setup\UninstallInterface
    {
        /**
         * {@inheritdoc}
         */
        public function uninstall(SchemaSetupInterface $setup, ModuleContextInterface $context)
        {
            ...
        }
    }
    

    비활성화된 모듈의 삭제 루틴(A disabled module's uninstall routine)은 그것이 삭제될 때 여전히 발생할 수 있다. 이뜻은 의존성주입 설정과 이벤트/오브저버 설정같은 모듈 특정의 설정(module specific configurations)은 사용가능하지 않을 것이며 문제를 발생시킬 수도 있다.  이를 피하기위해 삭제클래스(uninstall classes)는  이들에 의존하지 말아야한다.



어떻게 마젠토 2 를 설치할 것인가?

압축파일을 사용해서 쉬운 설치를 할것인가, 컴포저를  사용해서 메타패키지를 다운로드할 것인가, 아니면 코드를 마젠토 2 코드베이스에  제공할 것인가?


다음의 테이블을 참고하라

사용자 니즈설명

설치단계

시작 링크

쉬운설치, 커멘드라인 없음, 자체서버보유

약간의 기술적지식, 마젠토 서버에대한 커맨드라인 액세스

  1. 마젠토 소프트웨어가 담긴 압축파일을 다운로드.
  2. 위의 것을 직접 마젠토서버에  압축을 풀거나 네트워크관리자에 부탁을 한다.
  3. 셋업위자드 혹은 커맨드라인을 사용하여 마젠토를 설치.

Easy installation (own server)

공유호스팅, 쉬운설치, 커맨드라인 액세스 없음

웹호스팅사용, 기술적지식 적음. 마젠토서버에대한 액세스가 제한됨.

  1. 마젠토 소프트웨어가 담긴 압축파일을 다운로드.
  2. 위의 것을 마젠토서버에 푼다.
  3. 셋업위자드를 사용해서 마젠토를 설치.

Easy installation (shared hosting)

Integrator, packager

설치된 모든 컴포넌트에대한 콘트롤을 원함. 마젠토서버에대한 액세스있음.기술적지식 보유. 마젠토CE를 다른 패키지와 리패키지할 수도있음.

  1. 사용할 컴포넌트를 포함한 컴포저 프로젝트를 생성.
  2. 컴포저를 사용해서 패키지의존성을 업데이트함; 마젠토 메타패키지를 얻기위해 composer create-project를 사용.
  3. 커맨드라인 혹은 셋업위자드를 사용해서 마젠토를 설치.

Get the metapackage

디벨로퍼(Contributing developer)

마젠토 코드베이스에 코드제공, 기술적 지식보유, 자체 마젠토 개발 서버보유, 컴포저와 깃허브를 이해함.

  1. Magento 2 GitHub 저장소를 클론함.
  2. 컴포저를 사용해서 패키지의존성을 업데이트함.
  3. 커맨드라인 혹은 셋업위자드를 사용해서 마젠토 설치.

Clone the Magento repository

자신의 현재 상황을 위 테이블에 비추어  어떤 방식이 마젠토 2를 설치하는데 적합한지 판단.



원문 : http://devdocs.magento.com/guides/v2.0/install-gde/continue.html



'Cookbook' 카테고리의 다른 글

마젠토 어드민 계정(Admin Account)  (0) 2016.04.02

퍼블리싱 패키지(Publishing Packages)

패키지정의(Define Your Package)

다음정보를 갖고있는 composer.json 라는 이름의 파일을 당신의 패키지 루트(root)에 놓는다:

{
    "name": "your-vendor-name/package-name",
    "description": "A short description of what your package does",
    "require": {
        "php": ">=5.3.0",
        "another-vendor/package": "1.*"
    }
}

위의 것은 제공해야하는 최소한의 정보이다.This is the strictly minimal information you have to give.

패키지 네이밍에대한 더 자세한 정보와 패키지를 더 나은 문서화를 하는데 사용하는 필드에대한 설명은  about 을 참조.

파일 커밋(Commit The File)

당신은 아마 여기에대한 도움은 필요치 않을 것이리라.

퍼블리싱하기(Publish It)

당 사이트에 Login 혹은  register 하고 메뉴에서,  submit 버튼을 누른다.

일단 거기에있는 당신의 퍼블릭 저장소 URL(public repository URL)에 들어가면 당신의 패키지는 주기적으로 자동으로 크롤링(crawled) 될것이다. 당신은 단지 composer.json파일의 업데이트를 유지하면 된다.


원문 : https://packagist.org


+ Recent posts