顯示具有 Drupal 標籤的文章。 顯示所有文章
顯示具有 Drupal 標籤的文章。 顯示所有文章

2015年11月11日 星期三

Drupal 上傳檔案到AWS S3上的方法(Upload File to AWS S3 From Drupal)

1.先在Drupal 安裝兩個Modules

     1.S3 File System (https://www.drupal.org/project/s3fs)
     2.Libraries API (https://www.drupal.org/project/libraries)

2.安裝AWS SDK for PHP 2.x library

     1.下載AWS SDK for PHP 2.x library的zip檔 (不能下載3.x版本會有問題)
     下載參考網址:https://github.com/aws/aws-sdk-php/releases
     目前是下載Version 2.8.23版的zip檔(aws.zip)

     2.解壓縮aws.zip檔到drupal的sites/all/libraries/awssdk2的路徑下。
          *可以先在local環境解壓縮再上傳。也可以將zip檔上傳後用命令模式(如ssh)去解壓縮(使用tar) 。例如 tar xvf filename.tar

3.設定S3 File System


     1.到「設定(setting)」/ 「媒體(media)」/ S3 File System來設定與AWS S3連線的設定。如圖:


    2.進入S3 File System後先設定 「S3 Bucket Name」與「S3 Region」。然後展開「 顯示AMAZON WEB SERVICES CREDENTIALS」來設定 「Amazon Web Services Access Key」,「Amazon Web Services Secret Key」。如圖:


4.設定drupal內容類型的圖片或是檔案欄位 上載目的地為s3 file system

如下圖所示
















設定完後就可以測試啦!!!

測試結果:





* Drupal版本:7.37

2015年7月16日 星期四

當Drupal時出現Mysql has gone away的問題時怎麼處理

這兩天Drupal出現問題剛開始時是想要新增Content type時出現這樣的畫面
  
不知道該如何解決時都執行幾次後,整個Drupal竟然沒法進入了。會出現下面這個畫面:


上網爬了很久幾乎都是說要增加mysql的max_allowed_packet到16M以上及加大php的memory limit size。

那就把AWS EC2上的設定改一下囉(我的Drupal 是裝在EC2上)。
先來修改mysql的設定吧。
sudo vim /etc/my.cnf

按 i 輸入以下文字

[mysqld]
max_allowed_packet = 64M

然後按下esc後輸入:wq存檔離開
重新啟動 mysql

sudo service mysqld stop
sudo service mysqld start

但是發現drupal 可以進入了不會出現Additional uncaught exception thrown while handling exception的錯誤但是還是不能新增Content type。
只好改 max_allowed_packet =256M

並一起修改php memory limit
sudo vim /etc/php.ini
找到memory_limit按i輸入修改為
memory_limit = 256M
然後按下esc後輸入:wq存檔離開

重新啟動apache跟mysql
sudo service httpd stop
sudo service httpd start
sudo service mysqld stop
sudo service mysqld start

終於可以成功進入drupal 並新增content type了。
進入後終於找到元兇了.......
因為我之前有安裝過token這個module。

token module 是個需要很大memory的一個模組如果沒有需要的話就關閉好了。


註:後來發現網路上也有一篇再說這個問題的討論,裡面說是auto_nodetitle 這個module照成上述問題的,內有提供兩個patch檔,用來配合修改一下auto_nodetitlle.module後,這個問題應該算是解決了。

https://www.drupal.org/node/1391706


2015年1月6日 星期二

Drupal Feeds Import 要匯入『分類』的資料時會出現『Column not found: 1054 Unknown column 'vocabulary_machine_name' in 'where clause'』的處理方式

Drupal7 Feeds Import 要用CSV檔匯入資料時如果資料裏頭有欄位是『分類』(taxonomy)的資料,會出現『Column not found: 1054 Unknown column 'vocabulary_machine_name' in 'where clause'』的訊息。上網找很久的終於搞定了。先筆記起來免得以後忘記了。

需要更換下面的檔案。(舊檔請記得先改名後再上傳檔案)。

1./sites/all/modules/feeds/plugins/FeedsTermProcessor.inc

2./sites/all/modules/feeds/mappers/taxonomy.inc

3./modules/taxonomy/taxonomy.module

更新的檔案如下:


2014年9月17日 星期三

Drupal 7 如何看與編輯未發表的節點內容

要如何查看未發表的節點內容
官網上是這樣說的
In Drupal 7, users are not allowed to view any unpublished content by default, not even content created by themselves. By enabling 'View own unpublished content', you grant users access to their own unpublished content.
The only way to allow users access to all unpublished content in Drupal 7 (without using a contributed module), is to enable the permission 'Bypass content access control'.......

但是打開Bypass content access control'會有安全上的疑慮。

所以建議使用 View unpublished 模組來查看未發表(unpublished)節點內容。
The module View unpublished allows you to grant access for specific user roles to view unpublished nodes of a specific type. Access control is quite granular in this regard. Additionally, using this module does not require any modifications to your existing URL structure.

那要如何編輯未發表的節點內容呢?
照一般的權限編輯的話,編輯未發表的節點內容的下方並不會出現如下圖




這時候得安裝Override Node Options 模組來覆寫某角色對於某個content type之published option 將其打勾即可有權限來編輯此節點的 已發表/未發表








此時在編節點文章時就有勾選已發表/未發表 的選項了。




2014年7月15日 星期二

在Drupal 7用Features匯出匯入content_type

1.安裝features Module後進入  structure -> feature (架構/功能)


2.點選上方『Create Features』標籤,展開『內容類型(content_type)』

3.勾選要匯出的內容類型(勾選後會把內容類型裡面的內容都標記出來)

4.設定左邊匯出之相關資訊
    輸入名稱、描述、Package與版本。其中Packsge建議不要用預設的Feature,需改成其他的與此content_type相關的字眼。版本第一次就用7.x-1囉。然後就可以按下下方的Download feature鍵將剛剛設定的東西匯出來了。


5.匯出來後會是一個由Machine name-版本組成檔名的一個壓縮檔如wheretogo-7.x-1.0.tar檔

6.用這個檔myacticle-7.x-1.0.tar可以到其他台機器上的Drupal用安裝新模組選擇此檔案的方式來匯入Content_type。但是要注意的是匯入的機器要安裝Features這個模組外。並在sites/all/modules/features這個路徑要有寫入的權限。




8.安裝如果沒有出現錯誤訊息的話,啟動此一新模組就可以再內容類型(Content Type)裡面看到這個內容類型了。




2014年6月25日 星期三

在Drupal Views裡如何用一個條件去篩選n個欄位的值

在Drupal Views裡如果要用一個條件去篩選n個欄位的值要怎麼做勒

步驟如下
1.「FILTER CRITERIA」點選『新增』(add)。
2. 在Add filter criteria頁面中使用搜尋欄位搜尋[ global ]。如下圖所示:


3.勾選Global: Combine fields filter選項。並按下方的Apply(all display)。

4.進入Configure filter criterion: Global: Combine fields filter頁面先勾選Expose this filter to visitors, to allow them to change it選項



5.輸入標籤(你想顯示在畫面上的文字)

6.下拉選擇『Operator』運算式。這有很多Operator如 is equal to(等於)、is not equal to(不等於)、Contains(包含)、Start with(起始於)等等......。本例是選擇Contains(包含)。

7.Value不填寫。但在Choose fields to combine for filtering項目中選擇要合併篩選的欄位。可以按著shift鍵來選擇多個項目。(注意:這些選擇的欄位必須是在FIELDS裡面有的欄位。)完成圖如下:



8.按下Apply(this display)鍵將設定結果起來。準備測試~

9.測試結果如果沒有問題的話記得將views儲存起來喔。


2014年3月2日 星期日

Drupal文章內容中增加超連結的CODE


這個例子是將超連結到存放zip檔的位置。
1.在文字格式選擇PHP CODE,且要可以在文字格式選擇PHP CODE要先開啟PHP Filter項目。

2.在編輯欄中輸入底下的CODE:
<?php
//抓目前的node id
$path= $_SERVER ['REQUEST_URI'];
$node_path = explode('/', drupal_get_normal_path($path));
$nodex=$node_path[3];
$nodex1=explode('?', $nodex);
//公用檔案存放路徑
$file_public_path=variable_get('file_public_path', conf_path() . '/files');
//ZIP檔存放路徑
$unzip_file_path=$file_public_path . '/unzipfiles/';
//第二層目錄
$sub_temppath=explode('/',$_SERVER['PHP_SELF']);
$sub_path=$sub_temppath[1]
;//組合第一層目錄+第二層目錄
$url='http://'.$_SERVER['HTTP_HOST'].'/'.$sub_path;
//顯示目前組合之超連結
echo '<a href=\''.$url.'/'. $unzip_file_path.$nodex1[0]. '/index.html\' target=\'_new\' >文件連結</a>';
?>

Drupal增加角色的方法圖示


Drupal 安裝pclzip module的步驟

  1. 先安裝Libraries API  http://drupal.org/project/libraries 
  2. 在Drupal中Enable Libraries Module
  3. 安裝pclzip 模組時要去download兩個東西。一個是pclzip的核心程式 pclzip.lib.php(http://www.phpconcept.net/pclzip/pclzip-downloads)下載最新版本(目前是2.8.2版)
  4.           另外一個是在Drupal用的module(http://drupal.org/project/pclzip)下載(pclzip-7.x-1.x-dev.tar.gz)
  5. 在Drupal網站路徑 sites/all/下新建一個libraries資料夾。如果是多網站環境下就是在 sites/all/<domain>/下新建一個libraries資料夾
  6. 在sites/all/libraries或是sites/all/<domain>/libraries資料夾內再建一個pclzip資料夾並把pclzip.lib.php放到此資料夾中。
  7. 在drupal中安裝pclzip-7.x-1.x-dev.tar.gz這個pclzip模組
  8. 修改pclzip.module file will be there in (pclzip module)
    Go to line# 79 - approx and replace the

    <?phpfunction pclzip_library_exists() {
     
    $pclzip_path = libraries_get_path('pclzip.lib.php');
      if (!
    is_file($pclzip_path)) {
       
    drupal_set_message(t('Could not find the PclZip library file : @pclzip_path', array('@pclzip_path' => $pclzip_path)), 'error');
        return
    FALSE;
      }
      return
    TRUE;
    }
    ?>
    WITH

    <?phpfunction pclzip_library_exists() {
     
    $pclzip_path = libraries_get_path('pclzip');
     
    $pclzip_path = $pclzip_path.'/pclzip.lib.php';
      if (!
    is_file($pclzip_path)) {
       
    drupal_set_message(t('Could not find the PclZip library file : @pclzip_path', array('@pclzip_path' => $pclzip_path)), 'error');
        return
    FALSE;
      }
      return
    TRUE;
    }
    ?>
  9. 在Drupal中Enable pclzip模組
  10. 一定要安裝Libraries API不然會出現miss libaries的錯誤。
補充作法:
Here if some one needs any help, you can use this as patch for now. I think the code that is written for now is wrong.
Do the following steps.
1- Download pclzip.lib.php
2- Create a folder named 'pclzip' inside your libraries folder (preferable - sites/all/libraries)
3- Copy pclzip.lib.php to sites/all/libraries/pclzip (folder) - the path might be diff you have created this folder else where
4- IMP and this is the patch.
Go to pclzip.module file will be there in (pclzip module)
Go to line# 79 - approx and replace the

<?phpfunction pclzip_library_exists() {
 
$pclzip_path = libraries_get_path('pclzip.lib.php');
  if (!
is_file($pclzip_path)) {
   
drupal_set_message(t('Could not find the PclZip library file : @pclzip_path', array('@pclzip_path' => $pclzip_path)), 'error');
    return
FALSE;
  }
  return
TRUE;
}
?>
WITH

<?phpfunction pclzip_library_exists() {
 
$pclzip_path = libraries_get_path('pclzip');
 
$pclzip_path = $pclzip_path.'/pclzip.lib.php';
  if (!
is_file($pclzip_path)) {
   
drupal_set_message(t('Could not find the PclZip library file : @pclzip_path', array('@pclzip_path' => $pclzip_path)), 'error');
    return
FALSE;
  }
  return
TRUE;
}
?>

Drupal PHP Filter

設定PHP Filter方法,可以參考下列影片


Drupal  7.17版本要使用PHP CODE的方法
1.在內容類型新增欄位時只能選到[長文字欄及摘要]
然後在下方的{文字格式}選擇[PHP CODE],這樣才能在編輯欄位裡輸入PHP碼。

或是
2.在新增區塊時在下方的{文字格式}選擇[PHP CODE]。這樣才能在[區塊內容]內輸入PHP碼。